Struts1中forward路径问题,求解啊~!!!
本帖最后由 lhtisgood 于 2013-11-11 22:55:27 编辑
这代码是照着书敲得,研究半天始终没有搞懂。
下面这是action类
package com.chinasei.struts.action;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import com.chinasei.struts.form.LoginForm;
public class LoginAction extends Action {
public ActionForward execute(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response)
{
LoginForm loginForm=(LoginForm) form;
String uName=loginForm.getUserName();
String uPassword=loginForm.getUserPassword();
if("Wangjg".equals(uName)&&"Wangjg".equals(uPassword))
{
return new ActionForward("success");
}
return new ActionForward("fail");
}
}
书中原来return值中,ActiongForward里的参数值分别是url地址pages/common/success.jsp与pages/common/fail.jsp,按照这样的写法网页的输出结果没有问题。
但是后来书中利用了修改struts-config.xml文件的方法:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://struts.apache.org/dtds/struts-config_1_2.dtd">
<struts-config>
<data-sources />
<form-beans>
<form-bean name="loginForm" type="com.chinasei.struts.form.LoginForm"/>
</form-beans>
<global-exceptions />
<global-forwards/>
<action-mappings>
<action path="/logon" name="loginForm" parameter="pages/common/success.jsp" type="com.chinasei.struts.action.LoginAction">
<forward name="success" path="/pages/common/success.jsp"/>
<forward name="fail" path="/pages/common/fail.jsp"/>
</action>
</action-mappings>
<message-resources parameter="com.chinasei.struts.ApplicationResources" />
</struts-config>
在action的注册中又添加了forward,并将原来action里的url替换成修改后的逻辑名,如最上面的代码那样.结果就出错了。。。。
是ActionForward方法中的参数值有错,应该是url不能为逻辑名?还是什么意思?求各位大大们解答啊
------解决方案--------------------改成
return mapping.findForward("success");