• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

HTTP Status 404 - /HelloWorld

 
Ranch Hand
Posts: 384
MyEclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ?



 
Sheriff
Posts: 22784
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 1514
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
naveen yadav
Ranch Hand
Posts: 384
MyEclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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



Still getting same error.


 
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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

 
naveen yadav
Ranch Hand
Posts: 384
MyEclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Change action=”org.HelloWorld” to action=”poi”. Because poi is the name of your HelloWorld servlet.
 
Bear Bibeault
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Bear Bibeault
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Bear Bibeault
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.

 
naveen yadav
Ranch Hand
Posts: 384
MyEclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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

 
naveen yadav
Ranch Hand
Posts: 384
MyEclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Daniel Val
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
naveen yadav
Ranch Hand
Posts: 384
MyEclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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

 
Rob Spoor
Sheriff
Posts: 22784
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your form action is "hello". That must mean you must have a url-mapping for "hello". You don't. Therefore it fails.
 
Bear Bibeault
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One more time: the form action should be the servlet context followed by the servlet mapping.
 
naveen yadav
Ranch Hand
Posts: 384
MyEclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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)









 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic