struts 新手并尝试通过基本教程并收到错误 InvalidPathException: No action config found for the specified url
我爆炸的网址是:http://localhost:8080/UserAction.do?method=add
这是我的 struts-config.xml 的一部分
<struts-config>
<form-beans>
<form-bean name="UserForm" type="Form.UserForm" />
</form-beans>
<action-mappings>
<action path="/user" type="Action.UserAction" input="/pages/user.jsp" parameter="method" name="UserForm" scope="session">
<forward name="success" path="pages/user.jsp">
</action-mappings>
</struts-config>
我的用户操作.Java
public class UserAction extends DispatchAction {
public ActionForward add(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
//Do some stuff
UserForm userForm = (UserForm)form;
userForm.setMessage("Added user");
return mapping.findForward("success");
}
}
这是用户表单
public class UserForm extends ActionForm {
private String message;
public UserForm() {
super();
}
public String getMessage() { return this.message; }
public void setMessage(String inMessage) { this.message = inMessage; }
}
最后我的 user.jsp
<html>
....
<html:form action="user">
<table>
<tr>
<td>
<html:submit value="add" onClick="submitForm()" />
</td> </tr></table></html:form>
</html>
提交表单很简单
function submitForm(){
document.forms[0].action = "UserAction.do?method=add"
document.forms[0].submit();