s:url link returns 404 "The requested resource is not available"

s:url link returns 404 "The requested resource is not available"

当我点击这个 link,放在 Login.jsp,我得到一个错误 "The requested resource is not available."

<s:url id="register_url" action="registerLink" />
<s:a href="%{register_url}"> Register </s:a>

Login.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html ">
<html>
    <head>
        <title>Biblioteka</title>
    </head>
    <body>
         <s:url id="register_url" action="registerLink" />
         <s:a href="%{register_url}"> Register </s:a>
         <div class="login-div">
            <s:actionerror escape="false" />
            <s:actionmessage escape="false" />
            <s:form action="login" method="post">
                <s:textfield name="memberBean.email" label="E-mail" />
                <s:password name="memberBean.password" label="Fjalëkalimi" />
                <s:submit value="Dërgo" />
            </s:form>
        </div>
    </body>
</html>

此外,如果我将这个 s:url 标签放在 Home.jsp 中,它 link 就完美了。

struts.xml的内容

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
 "-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
 "http://struts.apache.org/dtds/struts-2.5.dtd">
<struts>
 <constant name="struts.enable.DynamicMethodInvocation" value="true" />
 <constant name="struts.devMode" value="true" />
 <constant name="struts.custom.i18n.resources" 
           value="ApplicationResources"/>


<package name="default" namespace="/" extends="struts-default">

    <interceptors>
        <interceptor class="org.ikubinfo.biblioteka.interceptor.LoginInterceptor"
            name="loginInterceptor">
        </interceptor>
        <interceptor-stack name="loginStack">
            <interceptor-ref name="loginInterceptor" />
            <interceptor-ref name="defaultStack" />
        </interceptor-stack>
    </interceptors>


    <!-- login action -->
    <action name="login" class="org.ikubinfo.biblioteka.controller.LoginAction">
        <result name="error">/WEB-INF/view/Login.jsp</result>
        <result name="success" type="redirect">home</result>
    </action>

    <!-- home link action -->
    <action name="home" class="org.ikubinfo.biblioteka.controller.LoginAction"
        method="home">
        <interceptor-ref name="loginStack" />
        <result name="error">/WEB-INF/view/Login.jsp</result>
        <result name="success">/WEB-INF/view/Home.jsp</result>
    </action>

    <!-- logout action -->
    <action name="logout" class="org.ikubinfo.biblioteka.controller.LoginAction"
        method="logout">
        <result>/WEB-INF/view/Login.jsp</result>
    </action>

    <!-- register action -->
    <action name="register"
        class="org.ikubinfo.biblioteka.controller.RegisterAction" method="execute">
        <result name="error">/WEB-INF/view/Register.jsp</result>
        <result name="input">/WEB-INF/view/Register.jsp</result>
        <result name="success">/WEB-INF/view/RegistrationSuccess.jsp</result>
    </action>


    <!-- register link -->
    <action name="registerLink"
        class="org.ikubinfo.biblioteka.controller.RegisterAction" method="redirect">
        <result>/WEB-INF/view/Register.jsp</result>
    </action>

</package>

id 属性已弃用。请改用 var。如果包中有命名空间,请使用命名空间属性。使用 # 引用上下文变量。不要在变量名中使用下划线。

<s:url var="registerUrl" namespace="/" action="registerLink" />
<s:a href="%{#registerUrl}">Register</s:a>