• 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

404 error mapping two servlets

 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
in my app-web I made two servlets. and two files jsp.
the first file jsp (CREATE.JSP) has a form, and send the data to the first servlet (SAVESERVLET), and it conects to the postgresql. all it's ok, all is working perfectly.
the second file jsp (DELETE.JSP) also has a form, and send the data (indeed, a int-id) to the second servlet (DELETESERVLET) and it should connects to the postgresql.
the problem is: I get a error 404 when I try send the data using second file jsp to the second servlet.
I have looked at the files jsp, the servlets, and the web.xml.
I am stucked at this point several days.

in the folder of context (myapp) I have the two files jsp (CREATE.JSP) and (DELETE.JSP)
in the folder myapp/WEB-INF/classes I have the two servlets (SAVESERVLET.CLASS) and (DELETESERVLET.CLASS). and the others classes (DAO, CONTACT).
in the folder myapp/WEB-INF/ I have the web.xml

code of web.xml:




in the CREATE.JSP, the code:


in the DELETE.JSP, the code:



why I get the error 404 in the second servlet?

 
Sheriff
Posts: 67746
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
Two things:
  • Servlets should be in a package other than the default.
  • Action URLs should be server-relative, not page-relative.


  • See the ServletsFaq and JspFaq for more details.
     
    ronald silva
    Ranch Hand
    Posts: 34
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    but...  is it impossible use the servlets without packages?
    I really couldn't understand why I get the error 404.
    the both servlets ar in the same folder. (indeed all servlets are in the same folder).
    the files jsp are pointting to the servlets. (each jsp to each servlet).
    I go on lost...

     
    ronald silva
    Ranch Hand
    Posts: 34
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    I put the servlets in a package. I have changed the web.xml. but... it didn't result in success...
     
    Bartender
    Posts: 1845
    10
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    It may be possible to use servlets without a package, but there are issues associated with it.
    The recommendation has ALWAYS been to use a package to avoid the problems.
    However that wouldn't be the cause of the 404 error.

    What is the URL of the page displaying delete.jsp? i.e. what shows in the location bar of your browser?
    Because you are using a relative link it may not go to the delete servlet like you want it to.

    I would expect:
    http://localhost:8080/myapp/delete.jsp
    When you push the delete button it should go to
    http://localhost:8080/myapp/deleteservlet.do

    With what you have shown here, it looks like it should work.
    Can you see the actual URL that it is requesting?

     
    reply
      Bookmark Topic Watch Topic
    • New Topic