struts初学疑问
按照书上的范例写了一个jsp,结果报http 404。什么原因?
附:struts-config.xml:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!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>
<form-beans>
<form-bean name="registerForm" type="app.RegisterForm"/>
</form-beans>
<action-mappings>
<action path="/register"
type="app.RegisterAction"
name="registerForm"
input="/register.jsp">
<forward name="success" path="/success.html"/>
<forward name="failure" path="/failure.html"/>
</action>
</action-mappings>
</struts-config>
index.jsp:
<%@ taglib uri="/tags/struts-html" prefix="html" %>
<html>
<head></head>
<body>
<html:form action="/register">
UserName:<html:text property="username"/><br>
enter password:<html:password property="password1"/><br>
re-enter password:<html:password property="password2"/><br>
<html:submit value="Register"/>
</html:form>
</body>
</html>
谢谢!
问题点数:20、回复次数:9Top
1 楼SpHib(wait)回复于 2006-03-12 21:35:00 得分 0
你的registerForm没问题吧,这个404是什么错误不记得了。
最好能详细点。Top
2 楼plusjava(目木--你是我千万人中追寻的人- 千 寻)回复于 2006-03-12 21:38:41 得分 0
404是路径错误,最简单的一个错误Top
3 楼yanycw(退刀槽)回复于 2006-03-13 19:28:42 得分 0
RegisterForm:
/*
* Created on 2006-3-6
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package app;
import org.apache.struts.action.ActionForm;
/**
* @author kfzx-yancw
*
* TODO To change the template for this generated type comment go to Window -
* Preferences - Java - Code Style - Code Templates
*/
public class RegisterForm extends ActionForm {
protected String username;
protected String password1;
protected String password2;
public String getUsername () {return this.username;};
public String getPassword1() {return this.password1;};
public String getPassword2() {return this.password2;};
public void setUsername (String username) {this.username = username;};
public void setPassword1(String password) {this.password1 = password;};
public void setPassword2(String password) {this.password2 = password;};
}
RegisterAction:
/*
* Created on 2006-3-6
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package app;
import org.apache.struts.action.*;
import javax.servlet.http.*;
/**
* @author kfzx-yancw
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class RegisterAction extends Action {
public ActionForward execute (ActionMapping mapping,
ActionForm form,
HttpServletRequest req,
HttpServletResponse res) {
// ①Cast the form to the RegisterForm
RegisterForm rf = (RegisterForm) form;
String username = rf.getUsername();
String password1 = rf.getPassword1();
String password2 = rf.getPassword2();
// ②Apply business logic
if (password1.equals(password2)) {
return mapping.findForward("success");
}
// ④
return mapping.findForward("failure");
}
}
Top
4 楼lfkanglei(kanglei)回复于 2006-03-13 19:34:12 得分 0
<html:submit value="Register"/>??
Register 不对吧???Top
5 楼zhengjing01(百事可乐)回复于 2006-03-14 14:14:05 得分 10
<action-mappings>
<action path="/register"
type="app.RegisterAction"
name="registerForm"
input="/register.jsp">
<forward name="success" path="/success.html"/>
<forward name="failure" path="/failure.html"/>
</action>
你的<forward name="success" path="/success.html"/>
<forward name="failure" path="/failure.html"/>是不是应该放到
<global-forwards>
</global-forwards>里面?Top
6 楼yanycw(退刀槽)回复于 2006-03-14 22:12:39 得分 0
不行啊!谁能帮忙指正一下,谢谢!Top
7 楼TLL_kdtx(风雨历程)回复于 2006-03-15 11:46:47 得分 10
<struts-config>
<form-beans>
<form-bean name="registerForm" type="app.RegisterForm"/>
</form-beans>
<global-forwards>
<forward name="success" path="/success.html"/>
<forward name="failure" path="/failure.html"/>
</global-forwards>
<action-mappings>
<action path="/register"
type="app.RegisterAction"
name="registerForm"
input="/register.jsp">
<forward name="success" path="/success.html"/>
<forward name="failure" path="/failure.html"/>
</action>
</action-mappings>
</struts-config>
Top
8 楼TLL_kdtx(风雨历程)回复于 2006-03-15 11:47:42 得分 0
<struts-config>
<form-beans>
<form-bean name="registerForm" type="app.RegisterForm"/>
</form-beans>
<global-forwards>
<forward name="success" path="/success.html"/>
<forward name="failure" path="/failure.html"/>
</global-forwards>
<action-mappings>
<action path="/register"
type="app.RegisterAction"
name="registerForm"
input="/register.jsp">
</action>
</action-mappings>
</struts-config>Top
9 楼yanycw(退刀槽)回复于 2006-03-15 20:32:02 得分 0
搞定了,原来是少了个文件。谢谢!Top




