0

index.jsp を実行してユーザー名とパスワードを入力すると、「重大: 無効なパス /UserAuth が要求されました」というメッセージが表示されます。

ここに私のweb.xmlがあります:

<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
    <display-name>StrutDemo</display-name>

    <servlet>
        <servlet-name>action</servlet-name>
        <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
        <init-param>
            <param-name>config</param-name>
            <param-value>/WEB-INF/struts-config.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>action</servlet-name>
        <url-pattern>*.do</url-pattern>
    </servlet-mapping>
    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
</web-app>

ここに私のstruts-config.xmlがあります:

<struts-config>
    <form-beans>
        <form-bean name="UserLogin" type="jbeans.UserLogin" />
    </form-beans>

    <action-mapping>
        <action path="/UserAuth"
                type="controllers.UserAuthAction"
                name="UserLogin"
                scope="request"
                validate="false"
                input="index.jsp">
                <forward name="success" path="/success.jsp" />
        </action>

    </action-mapping>
</struts-config>

index.jsp:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
    <form method="POST" action="UserAuth.do">
        <input type="text" name="username" />
        <input type="text" name="password" />
        <input type="submit" />
    </form>
</body>
</html>

UserAuthAction.java:

public class UserAuthAction extends Action{

    public ActionForward execute(ActionMapping map, ActionForm form,
                                 HttpServletRequest req, HttpServletResponse res) throws Exception{
        System.out.println("Inside USERAUTHACTION");
        ActionForward nextPage = null;
        UserLogin loginInfo = (UserLogin) form;
        String userName = loginInfo.getUsername();
        String pwd = loginInfo.getPassword();
        System.out.println(userName + " " + pwd);
        nextPage = map.findForward("success");
        return nextPage;
    }

}

および UserLogin.java

public class UserLogin extends ActionForm{

    private String username;
    private String password;

    public String getPassword() {
        return password;
    }
    public void setPassword(String password) {
        this.password = password;
    }
    public String getUsername() {
        return username;
    }
    public void setUsername(String username) {
        this.username = username;
    }   
}

ありがとうございました!!!

4

0 に答える 0