Announcement Announcement Module
Collapse
No announcement yet.
How to call controller in other server, and handler result of called controller. Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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, 02:01 PM.

  • #2
    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).

    Comment


    • #3
      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.

      Comment

      Working...
      X