日期:2014-05-20  浏览次数:20659 次

struts做的一个登陆页面,运行报错!
login.jsp页面代码:
<form action="Login" method="post">
用户名:<input type="text" name="name"></input><br>
密码:<input type="password" name="pwd"></input><br>
<input type="submit" value="提交"></input>
</form>

LoginAction.java的代码:

public class LoginAction extends ActionSupport{
private String name;
private String pwd;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPwd() {
return pwd;
}
public void setPwd(String pwd) {
this.pwd = pwd;
}
@Override
public String execute() throws Exception {
if(getName().equals("aaa") && getPwd().equals("aaa") ){
return "error";
}
else{
return SUCCESS;
}
}

strutrs.xml的代码:

<struts>
<constant name="struts.devMode" value="true" />
<package name="default" namespace="/" extends="struts-default">
<action name="login" class="liu.action.LoginAction">
<result>/success.jsp</result>
<result name="error">/error.jsp</result>
</action>
</package>
</struts>

点击提交就报错:
如下:

HTTP Status 404 - /Myex/Login

--------------------------------------------

type Status report

message /Myex/Login

description The requested resource (/Myex/Login) is not available.


--------------------------------------------

Apache Tomcat/6.0.29


哪里出错了?

------解决方案--------------------
你struts配置文件里写的form提交路径是小写的login
而你表单提交的路径Login中L是大写的,当然404了,错误很明显
而且,你form表单中提交要加上.action,也就是login.action
------解决方案--------------------
探讨
下面好多人都说了这个login的大小写问题,可是改过来,报的错误还是一样。本人初学,问一下还有个web.xml需要配置吗?


引用:

<form action="Login" method="post">改为<form action="login.action" method="post">试试看。。大小写区分,注意加.action后缀。……

------解决方案--------------------
<action name="login" class="liu.action.LoginAction">和<form action="Login" method="post">中两个login大小写不一致。
在就是看web.xml中的配置对不对了
------解决方案--------------------
web.xml配置 如果你的struts版本在2.16以上,,配置如下:
Java code

    <filter>
        <filter-name>struts2</filter-name>
        <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
    </filter>

    <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>