I have a form in which I have :
JSP:
<form name="xyz" action="upload">
<input type="file" name="upload"/>
<input type="submit" name="submit" value="submit"/>
</form>
struts.xml
:
<action name="upload" class="uploadClass" method="saveExcel">
<result name="success">page1.jsp</result>
<result name="error">error.jsp</result>
</action>
For this it gives an error :
HTTP Status 404 - No result defined for action and result input
And if I modify struts.xml
as :
<action name="upload" class="uploadClass" method="saveExcel">
<result name="success">page1.jsp</result>
<result name="error">error.jsp</result>
<result name="input">page1.jsp</result>
</action>
When I try to submit the form the page reloads.
How to resolve this?
It's important to use encoding multipart/form-data
for your form if you are file uploading.
<form name="xyz" action="upload" enctype="multipart/form-data">
<input type="file" name="upload"/>
<input type="submit" name="submit" value="submit"/>
</form>
Struts were not accept your file sent by the request if it's not encoded to multipart/form-data
and file upload errors occurred. You can check what errors are using s:actionerror
or s:fielderror
tags in JSP. Default messages are configured using File Upload Error Messages.
Note, if your action has errors and you have default interceptor stack invoked the workflow
interceptor will return INPUT
result. It gives you refresh effect.