• Post Reply Bookmark Topic Watch Topic
  • New Topic

HTTP Status 404 - /ServletExample/HelloWorld

 
rajesh kumar swain
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am trying to learn jsp and servlet. I am getting this error while running the project.

I am providing the 3 files below.
HelloWorld.java


web.xml----->


Home.jsp


Please help me solving this problem.

 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65664
129
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please see the ServletsFaq for a list of possible causes for this issue.
 
rajesh kumar swain
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oh..
I was invoking wrongly.
I corrected the URL by http://localhost:8080/ServletExample/Home.jsp and it worked.

Previously i was trying http://localhost:8080/ServletExample/HelloWorld.

But no idea whether invoking this way is correct or not
 
rajesh kumar swain
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here one more question arise to me. I wanted to have /test/* in the url-pattern and wanted to invoke the JSP file. Is it possible. Because I am getting error. May be I am missing something. Please  help.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65664
129
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
rajesh kumar swain wrote:
Previously i was trying http://localhost:8080/ServletExample/HelloWorld.

That does not match what is in your web.xml, so that should not be a surprise.
 
rajesh kumar swain
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:
rajesh kumar swain wrote:
Previously i was trying http://localhost:8080/ServletExample/HelloWorld.

That does not match what is in your web.xml, so that should not be a surprise.


I did not get your  words. I have HelloWorld in web.xml
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65664
129
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, I missed the other declaration.

Have you gone through the list in the ServletsFaq? There's one obvious step you have not taken.
 
Stefan Evans
Bartender
Posts: 1826
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What other declaration?

I see a servlet called "Hello" which is in the servlet class "HelloWorld"
The servlet called "Hello" should be accessed using the url pattern "/HelloServlet"

Possibly you are mixing up the Servlet class with the URL you have defined to access the servlet?


Also, I think Bear is hinting at the fact that your Servlet class (and for that matter all java classes you right) needs to be in a package.
 
rajesh kumar swain
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I followed the link http://met.guc.edu.eg/OnlineTutorials/JSP%20-%20Servlets/A%20servlet%20example.aspx
As i told i am very new to servlet. But I am confused with how the servlet will be called?
using the jsp page
or
using the servlet name
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65664
129
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You use the URL mapping that you set up in the web.xml.
 
rajesh kumar swain
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think the URL mapping is required here first to be invoked.
As it has a JSP page and that jsp page uses a servlet for business logic. One need to invoke the JSP page first
 
Dave Tolls
Ranch Hand
Posts: 2369
25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You don't use the JSP page to get to a servlet.
That's backwards.

You should be making requests to a servlet that then either responds itself or forwards to a (hidden under WEB-INF) JSP page to display the result.
 
rajesh kumar swain
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks.
But then why I am getting error when i run the servlet directly.
I using java 8 and Marse 2 eclipse. Even i tried using annotations without using web.xml. But when i run JSP page it is working but when i run the servlet directly it is giving 404 error.
 
rajesh kumar swain
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok I am able to call the servlet now.

My code is
LoginServlet.java


LoginService.java


login.jsp


success.jsp


With these files I am able to run the servlet and then redirect to the login.jsp

Please let me know this is correct way of invoking or not
 
Do not threaten THIS beaver! Not even with this tiny ad:
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!