简体   繁体   中英

method of action class is not getting called in struts2

I am trying to call a method present in action class on click of submit button but method is not getting called. here is my code---this is jsp page

<body>
<s:form method="POST" >
<a href="<s:url action="goback"/>">click here to go back</a>
<s:submit action="fileUploadAction" value="UploadFile"/>
<s:file name="fileUpload" label="Select a File to upload" size="40"/>
</s:form>
</body>

and this is struts.xml

<struts>
<package  name="default" extends="struts-default">
<action name="fileUploadAction" class="com.cdac.cloud.HelloWorld" method="uploadFile">
<result name="successfulupload">/success.jsp</result>
<result name="exception">/error.jsp</result> 
</action>
</package>
</struts>  

earlier this submit button was in another page and it was working fine but when i moved it to another jsp page problems started

<body>
<s:form action="fileUploadAction">
<a href="<s:url action="goback"/>">click here to go back</a>
<s:submit value="UploadFile"/>
<s:file name="fileUpload" label="Select a File to upload" size="40"/>
</s:form>
</body>

Try this out..!

 <body>                             
 <s:form name="something">                                          
 <a href="<s:url action="goback"/>">click here to go back</a>  
 <s:submit onclick="javascript:submit();"/>  
 <s:file name="fileUpload" label="Select a File to upload" size="40"/>  
 </s:form>  
 </body>

Then in JS,

function submit()  
{  
document.something.action="<%= request.getContextPath()%>/fileUploadAction";  
document.something.submit();  
}

I did not test this code..! post a comment if it is working..!

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM