我用struts做了一个简单应用,为什幺form提交时,Action对象好象不执行?

catthunder 2005-03-09 08:18:31
Action对象会forward到success.html或failuer.html,但是实际执行时没forward到这两个页面。
大家说说大概会因为什么问题造成的?
Register.jsp:
<%@ taglib uri = "/WEB-INF/struts-html.tld" prefix = "html" %>
<html:form action = "jspbook.do">
UserName: <html:text property = "username"/><br>
enter password:<html:password property = "password1"/><br>
re-enter password:<html:password property = "password2" /><br>
<html:submit value = "jsbook" />
</html:form>
web.xml:
<web-app>
<taglib>
<taglib-uri>/WEB-INF/struts-html.tld </taglib-uri>
<taglib-location>/WEB-INF/struts-html.tld </taglib-location>
</taglib>
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<load-on-startup>1</load-on-startup>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
</web-app>
Action-mapping,action也在struts-config.xml中设定了。
Struts.xml:
<struts-config>
<form-beans>
<form-bean name = "registrationForm" type = "struts.RegistrationForm" />
</form-beans>
<action-mappings type = "org.apache.struts.action.ActionMapping">
<action path = "/jspbook" type = "struts.RegisterAction"
name = "registrationForm" input="/register.jsp">
<forward name = "success" path = "/success.html" />
<forward name = "failure" path = "/failure.html" />
</action>
</action-mappings>
<message-resources parameter="MessageResources" />
</struts-config>

...全文
105 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
xiaowenand 2005-03-09
  • 打赏
  • 举报
回复
程序是没问题!
catthunder 2005-03-09
  • 打赏
  • 举报
回复
知道了RegisterAction以前用的perform方法,后來改成execute后,未重新compile
wenchaohu213 2005-03-09
  • 打赏
  • 举报
回复
<action = "jspbook.jsp">吧

在前面的跳转不能实现的。
catthunder 2005-03-09
  • 打赏
  • 举报
回复
RegisterAction:
public class RegisterAction extends Action{
public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws IOException,ServletException
{
RegistrationForm rf = (RegistrationForm) form;
String username = rf.getUsername();
String password1 = rf.getPassword1();
String password2 = rf.getPassword2();
String target = "failure";
if (password1.equals(password2)){
target = new String("success");
}
return (mapping.findForward(target));
}
}
catthunder 2005-03-09
  • 打赏
  • 举报
回复
先看看action有没有执行
在action里打出form提交的值 ?

怎么看action有沒执行?在action里打form提交的值,怎么打?
xxgu 2005-03-09
  • 打赏
  • 举报
回复
struts.RegisterAction 这个应该是你的Action吧,在这里面你的forward是怎么指定的呢,看看代码
cpl3113 2005-03-09
  • 打赏
  • 举报
回复
你的action里怎么写的
先看看action有没有执行
在action里打出form提交的值

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧