日期:2014-05-17  浏览次数:20695 次

请教struts1x的dispatchAction问题
用struts1做开发,配置如下:
web。xml:
 
  <!-- 配置struts -->
  <servlet>
   <servlet-name>struts</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>0</load-on-startup>
  </servlet>
  <servlet-mapping>
   <servlet-name>struts</servlet-name>
   <url-pattern>*.do</url-pattern>
  </servlet-mapping>
  
 </web-app>


struts-config.xml:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.3//EN" "http://struts.apache.org/dtds/struts-config_1_3.dtd">
<struts-config>
<form-beans>
<form-bean name="employeeForm" type="com.cdtax.web.forms.EmployeeForm" />
</form-beans>
<action-mappings>
<action path="/login" parameter="method" name="employeeForm" type="com.cdtax.web.action.LoginAction">
<forward name="ok" path="/WEB-INF/mainFrame.jsp" />
<forward name="err" path="/WEB-INF/login.jsp" />
</action>
</action-mappings>
</struts-config>
login。jsp:
<body>
<h1>管理员登陆</h1>
<form action="/myssh/login.do?method=login" method="POST">
id:<input type="text" name="id" /><br>
pw:<input type="password" name="pwd" /><br>
<input type="hidden" name="method" value="login" />
<input type="submit" value="登陆" />
<input type="reset" value="重置" />
</form>
  </body>


form:
package com.cdtax.web.forms;

import org.apache.struts.action.ActionForm;

public class EmployeeForm extends ActionForm
{
private String id;
private String pwd;

        public String getId()
{
return id;
}
public void setId(String id)
{
System.out.println("form id" + id);
this.id = id;
}
public String getPwd()
{
return pwd;
}
public void setPwd(String pwd)
{
this.pwd = pwd;
}

}


action:
package com.cdtax.web.action;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

import com.cdtax.web.forms.EmployeeForm;

public class LoginAction extends DispatchAction
{

//响应登录请求
public ActionForward login(ActionMapping arg0, ActionForm arg1,
ServletReque