Results 1 to 2 of 2
  1. #1
    kosmos890 is offline Member
    Join Date
    Apr 2012
    Posts
    40
    Rep Power
    0

    Default How to write a Servlet that sends file to user to download

    I read this post How to write a Servlet that sends file to user to download
    I use NetBeans IDE.
    Java Code:
    [MyWebApp]
    	|-fileToDownload
    	|-[Web Pages]
    	|	|-[WEB-INF]
    	|	|-[pages]
    	|	|		|-page.jsp  (I call DownloadServlet here)
    	|	|-index.jsp
    	|
    	|-[Sources Packages]
    		|-org.downloadservlet
    			|-DownloadServlet.java
    I can't map the servlet to URL pattern
    Java Code:
      <servlet>
            <servlet-name>DownloadServlet</servlet-name>
            <servlet-class>org.downloadservlet.DownloadServlet</servlet-class>
        </servlet>
        <servlet-mapping>
            <servlet-name>DownloadServlet</servlet-name>
            <url-pattern>/DownloadServlet</url-pattern>
        </servlet-mapping>
    I tried to use a form or input
    Java Code:
    Download: <a href="${pageContext.request.contextPath}/DownloadServlet">Download Link</a>
    
    <form name="input" action="${pageContext.request.contextPath}/DownloadServlet">
            <input type="submit" value="Download">
    </form>
    
    <input type="button" value="Update" onclick="location.href='/DownloadServlet'">
    Using link and form to download : "HTTP Status 405 - HTTP method POST is not supported by this URL"
    Using input to download : "HTTP Status 404 - Not Found"

    How do I call DownloadServlet from JSP?

  2. #2
    kosmos890 is offline Member
    Join Date
    Apr 2012
    Posts
    40
    Rep Power
    0

    Default Re: How to write a Servlet that sends file to user to download

    Sorry for my silly mistake. The code works perfect.

    I put "Servlet" 's code into processRequest(request,response) but I forgot to call processRequest() from doGet() and doPost().

    Thanks to all for taking the time to read my post.

Similar Threads

  1. Replies: 4
    Last Post: 11-10-2011, 04:49 AM
  2. Replies: 13
    Last Post: 04-16-2010, 03:51 AM
  3. Replies: 6
    Last Post: 03-01-2010, 08:00 AM
  4. upload and download file using servlet
    By amit_m04 in forum Java Servlet
    Replies: 1
    Last Post: 09-27-2009, 04:06 AM
  5. can I user servlet without tomcat ?
    By alvandrood in forum Java Servlet
    Replies: 3
    Last Post: 09-01-2009, 08:30 AM

Posting Permissions

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