Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8429537
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T05:21:59+00:00 2026-06-10T05:21:59+00:00

The code below is from a book,so it’ll not be incorrect.But I don’t know

  • 0

The code below is from a book,so it’ll not be incorrect.But I don’t know how to solve this below error.When delete the method doGet(),the same error!

“HTTP Status 405 – HTTP method GET is not supported by this URL”

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class PDFServlet extends HttpServlet{
private static final long serialVersionUID = 1L;
@Override 
protected void doGet(HttpServletRequest request,HttpServletResponse response) 
throws IOException,ServletException{
    this.doPost(request,response);
}
@Override 
protected void doPost(HttpServletRequest request,HttpServletResponse response) 
                                   throws IOException,ServletException{
    response.setContentType("application/pdf");
    ServletOutputStream out=response.getOutputStream();
    File pdf=null;
    BufferedInputStream buf=null;
    try{
        pdf=new File("C:\\Users\\lk\\Desktop\\Desktop\\ example.pdf");
        response.setContentLength((int)pdf.length());
        FileInputStream input=new FileInputStream(pdf);
        buf=new BufferedInputStream(input);
        int readBytes=0;
        while((readBytes=buf.read())!=-1)    out.write(readBytes);
    }catch(IOException e){
        System.out.println("file not found!");
    }finally{
        if(out!=null) out.close();
        if(buf!=null) buf.close();
    }
}
}

web.xml:

<?xml version="1.0" encoding="UTF-8"?>
-<web-app xsi:.........." version="2.5"> 
-<servlet> 
<description>This is the description of my Java EE component</description> 
<display-name>This is the display name of my Java EE component</display-name> 
<servlet-name>PDFServlet</servlet-name> 
<servlet-class>PDFServlet</servlet-class> 
</servlet> 
-<servlet-mapping> 
<servlet-name>PDFServlet</servlet-name> 
<url-pattern>/PDFServlet</url-pattern> 
</servlet-mapping> 
-<welcome-file-list> 
<welcome-file>index.jsp</welcome-file> 
</welcome-file-list> 
-<login-config> 
<auth-method>BASIC</auth-method> 
</login-config> 
</web-app>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T05:22:01+00:00Added an answer on June 10, 2026 at 5:22 am

    The Servlet code seems correct.
    Provide web.xml entry and Servlet calling URL.

    There are two main reasons which cause this error:

    1) You do not have a valid doGet() method, when you type the servlet’s path in address bar directly, the web container like Tomcat will try to invoke the doGet() method.

    public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws IOException{
    ....
    }
    

    2) You made a HTTP post request from a HTML form, but you do not have a doPost() method to handle it. The doGet() can not handle the “Post” request.

    public void doPost(HttpServletRequest request, HttpServletResponse response)
    throws IOException{
    ....
    }
    

    Read @BalusC’s answer for more details. : doGet and doPost in Servlets

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I don't know where I've got a mistake, when I fire below code from
Please help, I got the code below from a book but it doesnt seem
I have the following simple code (see below) I copied from a book. But
From Accelerated C++ (book), I found this code which is identical program, but the
Below is a code snippet from a book. Why can serialNumber still be set
I am able to provide animation to an image button from below code. this.RegisterName(image1.Name,
The code below is from the book Beginning iPhone 3 Development , chapter 15,
The code below from http://www.scalaclass.com/book/export/html/1 to do matrix dot product. I can't understand the
Please have a look at the code below (excerpt from a C# book): public
the code below is from an assignment in my text book for a simple

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.