Results 1 to 3 of 3

Thread: How to call controller in other server, and handler result of called controller.

Hybrid View

  1. #1
    Join Date
    May 2012
    Posts
    2

    Default How to call controller in other server, and handler result of called controller.

    I have 2 webpage (java spring 2.5, MVC) name "web 1" and "web 2".

    - At "web 1", I have a controller name "controller 1".
    this controller will return a zip file to client, and allow client to download zip file.
    ----code controller 1-------
    Code:
    @Controller
    public class TransferFile {
    	@RequestMapping("/transfer.ws")
    	public ModelAndView TransferZipFile(HttpServletRequest request,
    			HttpServletResponse response) throws Exception {
    		String zipFileName = "zipfile.zip";
    		String zipFilePath = "c:/" + zipFileName;
    		InputStream in = new FileInputStream(zipFilePath);
    		response.setContentType("application/download");
    		response.setHeader("Content-Disposition",
    				"attachment; filename=\"" +  zipFileName + "\"");
    		response.setContentLength(in.available());
    		ServletOutputStream op = response.getOutputStream();
    		int length = 0;
    		byte[] buf = new byte[1024];
    		while ((in != null) && ((length = in.read(buf)) != -1)) {
    			op.write(buf, 0, length);
    		}
    		in.close();
                    op.flush();
    		op.close();
    		return null;
    	}
    }
    -----------------------------
    I was check download file ok.

    - At "web 2", i have a controller name "controller 2".
    this controller will call link of "controller 1", and saving zip file of "controller 1" to driver c.
    ----------
    I was try, but i can't saving zip file to driver c.

    Please help me.
    Thanks you very much.
    Last edited by vnvictor; Jul 21st, 2012 at 01:01 PM.

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,695

    Default

    Please use [ code][/code ] tags when posting code that way we can actually read your code ..

    1. Your content-type is weird
    2. You are reading/writing to C: at the same time and I suspect you are doing it with the same file.

    Also not sure what your problem is you are showing the controller sending the file, but have problems saving it, so I don't really see how that is related to the code you posted (you basically posted a single part of the problem).
    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

  3. #3
    Join Date
    May 2012
    Posts
    2

    Default

    Thanks Marten Deinum, i was change my post.
    My problem is: i can't cast zip download file by code to save it.

    I was try with ajax and socket to save zip file. but i was failed.

    help me, please.

    Thanks you very much.

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
  •