Forums Register Login

HTTP Status 404 - /HelloWorld

+Pie Number of slices to send: Send
hi ranchers ,

i have html form (index.html) which accepts the name from user




and the servlet file HelloWorld.java retrieve name of user and displays back to user



when i submit the html form i got HTTP Status 404 - /HelloWorld

note that i have not created any web.xml file

what is the problem here ?



1
+Pie Number of slices to send: Send
In HTML, / means the root of the server, not the root of the web application. Your action is looking one level too high.

Also, servlets need a web.xml file with servlet and servlet-mapping entries. Without these servlets will never work.
+Pie Number of slices to send: Send
Where is your servlet class located? My advice to you would be to make sure your servlet class is in a package, and put an entry that maps to your servlet in web.xml.
+Pie Number of slices to send: Send

here is web.xml under \WEB-INF dir.



Still getting same error.


+Pie Number of slices to send: Send
If you are not going to pay attention to the replies, why are you posting in the first place?

Bosun Bello wrote:My advice to you would be to make sure your servlet class is in a package

 
+Pie Number of slices to send: Send
Reason for not using package was that the servlet container will look for servlet in \WEB-INF\class directory by default.

but nervertheless i have placed HelloWorld in org package

so 1 line of code is changed in web.xml



also in index.html



Still
HTTP Status 404 - /SESSION/org.HelloWorld

+Pie Number of slices to send: Send
Change action=”org.HelloWorld” to action=”poi”. Because poi is the name of your HelloWorld servlet.
+Pie Number of slices to send: Send
 

naveen yadav wrote: Reason for not using package was that the servlet container will look for servlet in \WEB-INF\class directory by default.


While that is the base of the hierarchy, the classes must be in an explicit package. As of Java 1.4, classes in the unnamed default package cannot be imported.

You can argue with us, or you can learn how to do things correctly. The choice is yours.
+Pie Number of slices to send: Send
 

Khalil Salman wrote:Change action=”org.HelloWorld” to action=”poi”. Because poi is the name of your HelloWorld servlet.


While that is a step in the right direction, the action must be prefixed with the context path to ensure that it will work in all environments.
+Pie Number of slices to send: Send
 

naveen yadav wrote:
here is web.xml under \WEB-INF dir.



Still getting same error.




- url pattern must be something /HellowWorld/* something like that, not what you have there; I suggest you use url patter *.something, then you change the action of your form to whatever.something and the url pattern of the servlet to *.something - please put whatever you want instead of that. I don't like url patterns that look like that /whatever/* - it is nothing wrong with them but I had issues in the past.

- in WEB-INF/classes (note the name is slightly different than what you got) you gotta put the compiled *.class file not the Java file. No issue if .java and .class are in the same folder although this is a bad practice, but you have to compile it first.

- root package is ok, should work. It is a (severely) discouraged practice, but for testing you should be fine.

D.
+Pie Number of slices to send: Send
 

Daniel Val wrote:url pattern must be something /HellowWorld/* something like that, not what you have there


Nope. It can be what he has there -- though I would strongly advise against using ".html"

I don't like url patterns that look like that /whatever/* - it is nothing wrong with them but I had issues in the past.


There should be no issues and it is a more modern approach than the old-fashioned *.do patterns. If you had issues it was not due to the type of pattern used.

+Pie Number of slices to send: Send
 

Bear Bibeault wrote:

You can argue with us, or you can learn how to do things correctly. The choice is yours.



i was not arguing. i was explaining the reason why i use the default package there. that was a mistake and have learned to put class always in a package.


It's always helpful to learn from your mistakes because then your mistakes seem worthwhile.
Garry Marshall

+Pie Number of slices to send: Send

so finally it worked after doing some changes.


change in web.xml instead of using /index.html



in index.html file instead of using the /HelloWorld



thank you guys.
+Pie Number of slices to send: Send
 

Bear Bibeault wrote:

Daniel Val wrote:url pattern must be something /HellowWorld/* something like that, not what you have there


Nope. It can be what he has there -- though I would strongly advise against using ".html"



No, it is not that, please see his example:
- he's got a html page
- the form defined in it is with action="/HelloWorld"
- when he submits the form he wants to go to the servlet

So the servlet must be installed at the url pattern /HelloWorld/... that's what I was saying...

Bear Bibeault wrote:

I don't like url patterns that look like that /whatever/* - it is nothing wrong with them but I had issues in the past.


There should be no issues and it is a more modern approach than the old-fashioned *.do patterns. If you had issues it was not due to the type of pattern used.



True, and of course now I don't have issues with any of the approaches, but for the good old time sake I prefer the second one *.something...


D
+Pie Number of slices to send: Send

index.html -----invokes------->org.Hello //working fine

first.html<--------response-------or.Hello //working fine

the mapping for the above flow control




first.html----------invoke---------->org.FirstQue ............//problem first.html could not invoke the servlet FirstQue,


the mapping for above flow of control is




and error is HTTP Status 404 - /ProjSession/org/first

+Pie Number of slices to send: Send
Your form action is "hello". That must mean you must have a url-mapping for "hello". You don't. Therefore it fails.
+Pie Number of slices to send: Send
One more time: the form action should be the servlet context followed by the servlet mapping.
+Pie Number of slices to send: Send

Bear you will be surprised to see , in following code ACTION have servlet context followed by url mapping BUT giving Http-404





But following code is working fine
web.xml



the strange behavior may be because for the mapping of index.html(which is welcome file for the context)









Think of how dumb the average person is. Mathematically, half of them are EVEN DUMBER. Smart tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 5327 times.
Similar Threads
calling jsp directl from HTML form
Where I am going wrong in the example of JEE6 using @WebServlet
adding a servlet
form data not passing to servlet file
HTTP STATUS 404: requested resource is not available.
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 07:39:31.