Announcement Announcement Module
Collapse
No announcement yet.
Upload file. file property of bean always null. Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Upload file. file property of bean always null.

    Hi,
    I am trying to upload a file to the server. I found an example of how to do this in the documentation:
    htttp://static.springframework.org/spring/docs/1.2.x/reference/mvc.html#mvc-multipart

    I canīt get it to work. The file property of the bean is always null.
    I use commons-fileupload.jar and Spring 1.2.

    Here is my code:

    Code:
    <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
    	<property name="maxUploadSize"><value>100000</value></property>
    </bean>

    This is my controller:
    Code:
    <bean id="FileUploadController" class="xxx.FileUpLoadController">
    		<property name="commandClass"><value>xxx.FileUploadBean</value></property>
    		<property name="formView"><value>function</value></property>
    		<property name="successView"><value>function</value></property>
    </bean>
    The controller class. fileUploadBean.getFile() always return null.
    Code:
    public class FileUpLoadController
    	extends SimpleFormController
    {
    	protected ModelAndView onSubmit(HttpServletRequest httpServletRequest,
    		HttpServletResponse httpServletResponse, Object o, BindException e)
    			throws java.lang.Exception
    	{
    		FileUploadBean fileUploadBean = (FileUploadBean)o;
    
    		MultipartFile file = fileUploadBean.getFile();
    
    		if(file!=null)
    		{
    		}
    		return super.onSubmit(httpServletRequest, httpServletResponse, o, e);
    	}
    }
    The bean class:
    Code:
    public class FileUploadBean
    	implements Serializable
    {
    	private MultipartFile file;
    
    	public void setFile(MultipartFile file)
    	{
    		this.file = file;
    	}
    
    
    	public MultipartFile getFile()
    	{
    		return this.file;
    	}
    }
    My jsp-page:
    Code:
    <form id="functionForm" name="functionForm" method="post" action="/maps/crs_upload.smb" enctype="multipart/form-data">
    		<div id="funkdiv273" style="display: inline;">
    				<fieldset style="width: 70%;">
    					<legend>Svar</legend>
    					<div class="padd">
    						<table>
    							<tbody>
    								<tr>
    									<td colspan="2">
    										<input value="" class="input" name="file" style="" size="0" type="file">
    									</td>
    								</tr>
    							</tbody>
    						</table>
    					</div>
    					<div class="action-pane">
    						<input name="show" class="submit" value="Visa" onclick="javascript:runFunction('273', 'Svar')" type="button">
    						<input name="close" class="submit" value="Stäng" onclick="javascript:toggleVisibilityFunction('273');" type="button">
    					</div>
    				</fieldset>
    		</div>
    </form>

  • #2
    Hi,

    <bean id="FileUploadController" class="xxx.FileUpLoadController">
    <property name="commandClass"><value>xxx.FileUploadBean</value></property>
    <property name="formView"><value>function</value></property>
    <property name="successView"><value>function</value></property>
    </bean>

    modify the above to have a commandname
    Code:
    <bean id="FileUploadController" class="xxx.FileUpLoadController">
    		<property name="commandClass"><value>xxx.FileUploadBean</value></property>
    		<property name="formView"><value>function</value></property>
    		<property name="successView"><value>function</value></property>
    <property name="commandName" value="FileUpload" />
    </bean>


    <form id="functionForm" name="functionForm" method="post" action="/maps/crs_upload.smb" enctype="multipart/form-data">
    modify the jsp to contain the following

    Code:
    <form:form commandName="FileUpload" method="post" action="/maps/crs_upload.smb" enctype="multipart/form-data">

    Comment


    • #3
      Upload file. file property of bean always null.

      Hi,
      Thanks for your replay sami!
      But I donīt think it will work because I use Spring 1.2 and the form:form tag is not implemented in that version.
      Does anybody know how to solwe it with 1.2?

      Comment


      • #4
        Upload file. file property of bean always null.

        Does anybody have an idea of how to solve this?
        Please tell me!

        Comment

        Working...
        X