2012-11-01 28 views
1

新無動作中的支柱&試圖去通過一個基本的教程,並正在錯誤InvalidPathException:http://localhost:8080/UserAction.do?method=add找到指定的URL

:未找到指定的URL

我的網址含有炸燬的行動配置

這裏是我的一部分,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> 

我UserAction.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> 

submitForm簡單

function submitForm(){ 
    document.forms[0].action = "UserAction.do?method=add" 
    document.forms[0].submit(); 

回答

2

您配置的單個動作,映射到路徑/user。因此,調用此操作的URL是。在你的情況,因爲看起來你已經部署了應用程序作爲根應用程序,它應該是http://localhost:8080/user.do

我沒有看到用JavaScript提交表單的重點。特別是如果它唯一做的是將正確的路徑更改爲不正確的路徑。順便說一句,如果通過在其中一個輸入中按回車來提交表單,JavaScript代碼將被繞過。

您還應該更喜歡請求範圍的表單bean,並遵守Java命名約定(小寫包)