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

  • SEARCH
  • Home
  • 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 7902075
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T09:24:09+00:00 2026-06-03T09:24:09+00:00

I want to implement a servlet to get the parameters from the browser and

  • 0

I want to implement a servlet to get the parameters from the browser and insert into db using http post not http get.

the servlet will recieve params from a url such as this http://localhost:8080/NewServlet?firstname=me&middlename=you&lastName=secret&location=here , and insert into the db, but Its like I cant do it properly.

here is the piece of code am trying to run

  public class NewServlet extends HttpServlet {

  public void doPost(HttpServletRequest request,

  HttpServletResponse response)

  throws IOException, ServletException{

  response.setContentType("text/html");

  PrintWriter out = response.getWriter();  

  String firstName = request.getParameter("firstname");

  String middleName = request.getParameter("middlename");

  String lastName = request.getParameter("lastname"); 

  String location = request.getParameter("location");

  String result;

  java.sql.Connection connDB = null;

  try {

            Class.forName("org.postgresql.Driver");

        } catch (ClassNotFoundException ex) {

            Logger.getLogger(DBConnection.class.getName()).log(Level.SEVERE, null, ex);
        }

        try {

            connDB = DriverManager.getConnection("jdbc:postgresql://" + "localhost" + ":" + 5432 + "/" + "mydb", "username", "secret");

            connDB.setAutoCommit(false);

            System.out.println("Connection established : [" + connDB.toString() + "]");

            java.sql.Statement bankStmt = connDB.createStatement();

           java.sql.Statement stt = connDB.createStatement();

            bankStmt.execute("INSERT INTO full_names(firstname, secondname, lastname) VALUES('"+firstName+"', '"+middleName+"', '"+lastName+"' )");

            java.sql.Statement bnk =connDB.createStatement();

            bnk.execute("INSERT INTO employee_details(location) VALUES('"+location+"')");

           }

            connDB.commit();

        } catch (SQLException ex) {

            ex.printStackTrace();

            try {

                connDB.rollback();

            } catch (SQLException ex1) {

                ex1.printStackTrace();

                Logger.getLogger(DBConnection.class.getName()).log(Level.SEVERE, null, ex1);


            }
            Logger.getLogger(DBConnection.class.getName()).log(Level.SEVERE, null, ex);

        }




  out.println("<b><font color='blue'>Your FirstName is :</font></b>" 

  + "<b>"+ firstName +"</b>" + "<br>");

  out.println("<b><font color='blue'>Your Middle Name is :</font></b>" 

  + "<b>"+ middleName +"</b>" + "<br>");


  out.println("<b><font color='blue'>Your Last Name is :</font></b>"  

  + "<b>"+ lastName +"</b>");
  }
}

When I try to run the code using the url http://localhost:8080/NewServlet?firstname=me&middlename=you&lastName=secret&location=here

I get the following error:

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

type Status report

message HTTP method GET is not supported by this URL

description The specified HTTP method is not allowed for the requested resource (HTTP method GET is not supported by this URL).

  • 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-03T09:24:10+00:00Added an answer on June 3, 2026 at 9:24 am

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

    Well, this is already the whole answer at its own. You’re sending a GET request, but your servlet implementation doesn’t support it. According to the code you wrote, it only supports POST requests. You don’t have a doGet() implementation anywhere, but only doPost().

    I’m not sure what’s the functional requirement is and why this error is unclear to you, but to get your code to run, you should either send a POST request instead, or to rename doPost method to doGet in your servlet.


    Unrelated to the concrete problem, your code has other problems as well, among others SQL injection holes, DB resource leaking and mingling the view in the controller. To learn servlets properly, you may want to start at our servlets wiki page.

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

Sidebar

Related Questions

I want to implement a RESTful webservice for an Android App using JSON. Do
I want to generate raw xml from a REST service using Spring. Something is
So I'm trying to implement things mentioned in Spring's 3.1 blog post about From
I want to implement a Java HTTP server locally, I mean the server computer
I want to implement Spring REST methods. I tried Get and it works: @RequestMapping(value
I want implement in my software solution an VBA editor but in c# 3.0.
given this class definition: public class Frame { IFrameStream CapturedFrom; } I want implement
Microsoft has announce that WindowsLiveID become a OpenID provider . I want implement it
I want to implement an autocomplete feature with images in my website. I would
I want to implement file uploading with behaviour which is commonly seen in various

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.