Results 1 to 1 of 1

Thread: Get Path Variable with out annotation

  1. #1
    Join Date
    Feb 2009
    Posts
    135

    Default Get Path Variable with out annotation

    Hi,

    I need a spring controller to return images/file by reading it from Disk.

    I think there is 2 ways to make a call from client
    options
    Code:
    http://localhost/ams/spring/files/images/get?directory=WORKSHOP_INFRA&fileName=45_slogan.jpg
      http://localhost/ams/spring/files/images/get/WORKSHOP_INFRA/45_slogan.jpg
    my Controller to satisfy the option one url is

    Code:
    public class FilesController extends MultiActionController
    {
    	public ModelAndView getFile(HttpServletRequest request,HttpServletResponse response) throws Exception
    	{
    		String fileName = ServletRequestUtils.getRequiredStringParameter(request, "fileName");
    		String directory = ServletRequestUtils.getRequiredStringParameter(request, "directory");
                                   //My method to read file from disk and return the bytes
    		byte[] fileBytes =getFileInBytes(directory,fileName)
    		response.setContentType(fileName.substring(fileName.lastIndexOf(".") + 1));
    		response.setContentLength(fileBytes.length);
    		response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");
    		FileCopyUtils.copy(fileBytes, response.getOutputStream());
    		return null;
    	}
    
    }
    when I dynamically create the first URL in flex client and use it to render images, is not working, due to & special Char, and geting IP address etc etc.

    So thought to use the 2nd URL pattern, but all examples, I found are using annotation path variable etc.
    I am yet to learn annotations. so to get the file name and directory from the URL, I need to manually parse the URL using substring, last index etc. Is there any utility in Spring to get me the path varaiable, with out annotation.

    Thanks
    Last edited by kannanMugundan; Jan 25th, 2012 at 02:10 AM.

Tags for this Thread

Posting Permissions

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