This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Servlets and the fly likes doGet is never called no matter what I do! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "doGet is never called no matter what I do!" Watch "doGet is never called no matter what I do!" New topic
Author

doGet is never called no matter what I do!

Ben Synes
Ranch Hand

Joined: Jul 18, 2012
Posts: 54
This is really frustrating, and I guess theres a gap in the small knowledge I have attained over the last two weeks of playing with JSP, but in my code below, the doGet method is not being called. I assumed when entering the url and hitting the jsp page, its respective Servlet's doGet method is inherently called. It could be a mapping issue, as I have not changed the web.xml, because I prefer the annotation based approach.

I managed to get the doPost working, by using a form, but I do not want to submit a form, its just a page which will render a table of data, nothing more.

ListUsersServlet.java


listUsers.jsp


Any help on this would be greatly appreciated, I had a thorough search on the web since last night and all posts I found were about submitting forms, but this is just to retrieve a value from the servlet back to the jsp.

Thank you.
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4425
    
    8

When you say "hitting the JSP page" - what URL are you using? You shouldn't be directly going to the JSP address, you should be going to the servlet address, which then forwards to the JSP. Could that explain your problem?
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3720
    
  16
And why are you importing your servlet into your jsp page ?
A JSP is a servlet, so your servlet and jsp should be totally separate from each other - the only connection, as Matthew says, is that your servlet forwards to your JSP.


Joanne
Ben Synes
Ranch Hand

Joined: Jul 18, 2012
Posts: 54
Hi

I'm hitting the URL like so
Http://localhost:8080/listUsers.jsp

The import statement was left there just as a test to see whether I could access a static method in the servlet.

So you are saying I should hit the URL:

Http://localhost:8080/listusersservlet

Like that??
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4425
    
    8

You should hit the URL you've mapped to the servlet. Based on your annotations, that looks like it should be http://localhost:8080/listUsers

If you use the JSP address the request is routed directly to the JSP, and never goes anywhere near the servlet.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: doGet is never called no matter what I do!