Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

404 error mapping two servlets

 
ronald silva
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • 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?

 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65227
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
    Greenhorn
    Posts: 15
    • Mark post as helpful
    • send pies
    • 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
    Greenhorn
    Posts: 15
    • Mark post as helpful
    • send pies
    • 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...
     
    Stefan Evans
    Bartender
    Posts: 1784
    10
    • Mark post as helpful
    • send pies
    • 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?

     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic