I have 2 actionClasses, one is called on startup. I'm trying to call an action with a button press (for now) that goes to another page and prints a message in the console saying this action was successful, but when I click on it it isn't called. Am I doing something wrong?
struts.xml
<struts>
<package name="default" extends="struts-default">
<action name="*" class="actionPackage.ActionClass1">
<result name="homepage">/default.jsp</result>
<result name="myNextPage">/nextPage.jsp</result>
</action>
</package>
</struts>
actionClass1
public String execute(){
System.out.println("the web application is working properly!");
return "homepage";
}
actionClass2
public String execute(){
System.out.println("the button works!");
return "myNextPage";
}
default.jsp
function strutsTestFunc(){document.getElementById("querySubmitter").submit()}
...
<form name="searchForm" method="post" action="actionPackage.ActionClass2" id="querySubmiter">
...
<input id="filterSubmit" type="submit" value="Search" onclick="strutsTestFunc()">
When I click the button it goes to "/actionPackage.ActionClass2" and gives me a 404 error. is there something I'm doing wrong here?
You mappings are wrong. Also avoid using *
wildcard to map all actions, bypassing in fact the framework mechanisms.
<struts>
<package name="default" extends="struts-default">
<action name="action1" class="actionPackage.ActionClass1">
<result name="homepage">/default.jsp</result>
</action>
<action name="action2" class="actionPackage.ActionClass2">
<result name="myNextPage">/nextPage.jsp</result>
</action>
</package>
</struts>
in JSP, always point to the mapping of the action, not to the action class itself:
<form action = "action2"
name = "searchForm"
method = "post"
id = "querySubmiter" >
After it works, start using default results like SUCCESS, and submit with <s:submit />
struts tag, that does not require javascript.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.