Search code examples
javarestjspjstlscriptlet

Rest Call in not working


I am trying to consume a rest call, which takes location of file in os. In return the rest call simulates a download of the file.

bellow is the code

<div class="form-container">
        <h1>Welcome to CoinPay</h1>

        Click on below links to download Coin.<br /><br />

         <a href="<c:url value='/download/<%=request.getParameter("dest") %>' />">Coin Mobile
            Application</a>


    </div>

In parameter "dest" values is D:/coinFiles/Coin-v1.1.8.apk.

The rest calls defination is given bellow

@RequestMapping(value="/download/{dest}", method = RequestMethod.GET)
    public void downloadFile(HttpServletResponse response, @PathVariable("dest") String dest) throws IOException {
}

for some reason the link created by href is not able to access the rest call.

How should I do this. Any help is appreciated. Thank you in advance.


Solution

  • If you want to create links like /download?dest=testDest you can use <c:param>.

    <c:url value="/download" var="myURL">
       <c:param name="dest" value="${dest}" />
    </c:url>
    
    <a href="${myURL}" />${myURL}</a>
    

    And Please change your controller.@RequestParam

    @RequestMapping(value="/download", method = RequestMethod.GET)
    public void downloadFile(HttpServletResponse response,@RequestParam("dest") String dest) {
         .......
    }