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