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 7755475
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:34:42+00:00 2026-06-01T12:34:42+00:00

Problem: Only doGet gets called when I expect doPost to be called. I have

  • 0

Problem: Only doGet gets called when I expect doPost to be called.

I have an embedded Jetty server that I start as follows:

server = new Server(8080);
ServletContextHandler myContext = new ServletContextHandler(ServletContextHandler.SESSIONS);
myContext.setContextPath("/Test.do");
myContext.addServlet(new ServletHolder(new MyServlet()), "/*");

ResourceHandler rh = new ResourceHandler();
rh.setResrouceBase("C:\\public");

HandlerList hl = new HandlerList();
hl.setHandlers(new Handler[]{rh, myContext});

server.setHandler(hl);

//server.start() follows

After I start the server, I open up the following page (resides in “public” folder, and opened via http://localhost:8080/test.html):

<html>
<head><title>Test Page</title></head>
<body>
<p>Test for Post.</p>
<form method="POST" action="Test.do"/>
<input name="field" type="text" />
<input type="submit" value="Submit" />
</form>
</body>
</html>

When I press the Submit button, I expect my servlet’s doPost method to be called, however doGet seems to be getting called instead. MyServlet class (extends HttpServlet) contains:

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
  System.out.println("   doGet called with URI: " + request.getRequestURI());
}

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
  System.out.println("   doPost called with URI: " + request.getRequestURI());
}

I never get the doPost print, just the one from doGet (on Submit button press).

Obviously, Jetty (and web technology in general) is brand new to me. I’ve been combing through the Jetty examples, but just can’t seem to get a POST to actually get picked up by the doPost method.

Appreciate any help. Thanks in advance.

  • 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-01T12:34:43+00:00Added an answer on June 1, 2026 at 12:34 pm

    The problem is your context path. B/c the path is set as

    myContext.setContextPath("/Test.do");
    

    Jetty is returning an HTTP 302 Found with a location that tells the browser “get the page from here”:

    HTTP/1.1 302 Found
    Location: http://localhost:8080/test.do/
    Server: Jetty(7.0.0.M2)
    Content-Length: 0
    Proxy-Connection: Keep-Alive
    Connection: Keep-Alive
    Date: Wed, 04 Apr 2012 19:32:01 GMT
    

    The actual page is then retrieved with a GET. Change the contextPath to / to see your expected results:

    myContext.setContextPath("/");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have working registration script the only problem is that i do not know
The problem I'm having is that any 'delete' action that gets called in IE-7
UPDATE: I've realized that the below problem only occurs if the user has already
Note: This problem occurs only on Mac, on Windows works fine. I have a
semi Resolved It appears that the problem exists only when running in debug mode,
I have an odd problem that I just can't seem to diagnose, and it
This problem only occurs in Internet Explorer 8 & 9 I have two dropdowns
First of all: This question is not directly programming related. However, the problem only
The problem is only happening with one file when I try to do a
This problem is only in IE. Consider the following HTML: <html> <body> <div style='position:absolute;left:1em;right:1em;top:1em;bottom:1em;overflow:auto;>

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.