Results 1 to 9 of 9

Thread: Annotated controller and requestParam

  1. #1
    Join Date
    May 2008
    Location
    Colombo, Sri Lanka
    Posts
    19

    Exclamation Annotated controller and requestParam

    Hi All,

    I'm trying to submit multipart data along with three hidden field values. And try to get those values using requestParam in annotated controller. code fragement as follows.

    Code:
       @RequestMapping(value ="/content_upload/upload_new_picture.htm", method = RequestMethod.POST)
    	public ModelAndView uploadNewVideo(@RequestParam("textfield") MultipartFile file, 	
                                           @RequestParam("mediaId") String mediaId,
                                           @RequestParam("contentId") String contentId, 
                                           @RequestParam("position") String position)throws IOException{
    		logger.info("upload: "+mediaId+" "+contentId+" "+position);
    		return new ModelAndView("content_upload/SMS");
    	}
    The HTML form I used is,
    HTML Code:
             <form name="frmFileUpload" id="frmFileUpload" method="post" enctype="multipart/form-data">
                   <input name="textfield" type="file" class="browse_button_field" id="textfield" size="35" />
    	       <input type="hidden" name="mediaId" id="mediaId"/>
    	       <input type="hidden" name="contentId" id="contentId" />
    	       <input type="hidden" name="position" id="position" />
            </form> 
    when I clicked the submit button it gives the following error message.

    Required org.springframework.web.multipart.MultipartFile parameter 'textfield' is not present

    When I removed the multipart data from the HTML form and the controller it working very well.
    Does anyone know Y is that? Can't we send the multipart data along with normal data.

    Plzzz help me to solve this issue.

    Regards,

    Rumesh

  2. #2
    Join Date
    Dec 2007
    Location
    Kerala, India
    Posts
    66

    Default

    i have a method and thats work fine for me
    Code:
     @RequestMapping("/imageUpload")
        public String processImageUpload(
                @RequestParam("name") String name, @RequestParam("description") String description,
        @RequestParam("image") MultipartFile image, HttpServletRequest request, HttpServletResponse response) throws IOException {

    Nidhin

  3. #3
    Join Date
    Aug 2008
    Posts
    1

    Default

    I'm having the exact same problem. I have found a workaround:

    Code:
    @RequestMapping(method = RequestMethod.POST)
    public String processSubmit(@RequestParam("name") String name,
    			@RequestParam("description") String description,
    			DefaultMultipartHttpServletRequest req) throws IOException {
    	MultipartFile file = req.getFile("textfield");
    	System.out.println("data:" + new String(file.getBytes()));
    
    ...
    It would be nice to know what the actual problem is though. I suspect that there is a Spring bug there somewhere.

  4. #4
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,632

    Default

    If you think it is a bug, register a JIRA for it. We cannot fix bugs we don't know about.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  5. #5
    Join Date
    May 2008
    Location
    Colombo, Sri Lanka
    Posts
    19

    Default GOT IT... Thanks

    Thanks Buddy, Sorry for the delay
    Its working!!!

    Regards,

    Rumesh

  6. #6
    Join Date
    Nov 2008
    Posts
    2

    Default How did you finally got it to work?

    I am still having problems with the same issue, I am using your code and still giving me problems, it says:

    "org.springframework.web.util.NestedServletExcepti on: Request processing failed; nested exception is java.lang.IllegalArgumentException: argument type mismatch"


    This is my form:

    "<form name="frmFileUpload" id="frmFileUpload" action="attachmentConvert.spr" method="post" >
    <table>
    <tr>
    <td><label>Archivo:</label></td>
    <td><input name="textfield" type="file" id="textfield" size="35" /></td>
    </tr>
    </table>

    <input type="submit" value="Create"/>
    </form>"

    This is my controller:

    @RequestMapping(value="/attachmentConvert.spr", method = RequestMethod.POST)
    public ModelAndView attachmentConvert(
    MultipartHttpServletRequest req) throws IOException {

    MultipartFile file = req.getFile("textfield");
    System.out.println("data:" + new String(file.getBytes()));
    return new ModelAndView("content_upload/SMS");


    }

  7. #7
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,632

    Default

    1) Your submission method is wrong (post should be multipart)
    2) You don't use a file input field but plain text

    So without that it is never going to work.

    For future posts use the [ code][/code ] tags....
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  8. #8
    Join Date
    Nov 2008
    Posts
    2

    Default

    This is the last thing I have done and it is still not working, any help will be great, thanks a lot!

    HTML File:

    Code:
    <html>
    <head><title>Simple html page</title></head>
        <body>
            <form name="frmFileUpload" id="frmFileUpload" action="attachmentConvert.spr" method="post" enctype="multipart/form-data">
                <table>
                    <tr>
                        <td><label>File:</label></td>
    
                        <td><input type="file" name="file" id="file"size="40" ></td>
                    </tr>
                </table>
    
                <input type="submit" value="Create"/>
            </form>
        </body>
    </html>
    Java Controller:

    Code:
    @Controller
    @RequestMapping("/attachmentConvert.spr")
    public class AttachmentConvertController {
    
        @Autowired
        MeasureManager measureManager;
    
        @RequestMapping(method = RequestMethod.POST)
        public String processSubmit(@RequestParam("file")MultipartFile file) throws IOException {
    
            System.out.println("data:" + new String(file.getBytes()));
    
            return "success";
    
    
        }
        
        
    
    }

  9. #9
    Join Date
    Jan 2007
    Posts
    20

    Default

    Maybe you've missed the

    Code:
    <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"/>
    in your applicationContext.xml?

    HTH,
    Kornel

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •