Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Problem : Upload Files With Struts FreamWork!

  Asked By: Pedro    Date: Mar 30    Category: Java    Views: 1325
  

i hava a problem with upload files with Struts fream
work!
My JSp Form Is:


<html:form enctype="multipart/form-data"
name="UploadForm" action="/webStruts/sendToBulk.do"
method="POST" >
<html:file property="file" ></html:file>
<Html:submit property="submit" value="upload" />
</html:form>

and my servlet is:
....
uploadFile(request,UploadForm.getFile());


UploadForm is my ForamBean...
but i run this servlet this error ocurred..
IO EXception :Corrupt form data: premature ending

i test this project with JSP/Servlet Model 2 but did
not this error

Share: 

 

1 Answer Found

 
Answer #1    Answered By: Chau Tran     Answered On: Mar 30

I think you created a servlet but you must use the
StrutsAction Servlet in your web.xml and create an
Action class and struts-config.xml (which this new
action sepecified in it with your path sendToBulk.do)

I don't know that you are aware of these issues or
not?
So you can not use a Servlet for your purpose you must
use struts  ActionServlet as shown in this snip of
web.xml


<servlet>
<servlet-name>action</servlet-name>

<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
<init-param>
<param-name>debug</param-name>
<param-value>2</param-value>
</init-param>
<init-param>
<param-name>detail</param-name>
<param-value>2</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>

And the create an Action class and then configure it
in a struts-config.xml file which is placed beside
web.xml in WEB-INF directory and specify in its
configuration your path (for example: sendToBlock) as
shown in the following snip of struts-config.xml

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts
Configuration 1.1//EN"

"http://jakarta.apache.org/struts/dtds/struts-config_1_2.dtd">

<struts-config>

<!-- Form Bean Definitions -->
<form-beans>
<form-bean name="testForm"
type="com.test.web.forms.TestForm"/>

</form-beans>

<action-mappings>
<action path="/sendToBulk"
type="com.test.web.actions.TestAction"
parameter="dispatch"
name="testForm" scope="request"
validate="false" input="/main/test.jsp">
</action>
</action-mappings>

</struts-config>

You must configure your struts completely to use its
features!

> Dear mr. dolatshahi!
tnx for u'r answer!
for upload  file with struts i write a :
1- (sendToBulk.do) ActionServlet for upload a file
with struts.
2- create a form bean that have property (FormFile)
with setter and getter Method.
3- create a jsp file that u see it's
code...(Multi-part form)
4- add a commons-upload,jar to classpath.
but when i run my project(for upload file) get this
error : IO EXception :Corrupt form data: premature
ending

however! can i use from FormFile Class that struts is
inroduce to me? (this class have a getInputsetram
method that get to me content of uploaded file)

 
Didn't find what you were looking for? Find more on Problem : Upload Files With Struts FreamWork! Or get search suggestion and latest updates.




Tagged: