*
The moose likes Servlets and the fly likes Servlet and XML result HTTP 404 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlet and XML result HTTP 404 " Watch "Servlet and XML result HTTP 404 " New topic
Author

Servlet and XML result HTTP 404

Alen Mester
Greenhorn

Joined: Jul 08, 2011
Posts: 21
Hello!!!

I have problem.....

My program is this one

THE SERVLET





THE JSP



The Idea is this one, when I put a number "1" on the ID search and enter, the next window have to show me the data of the database/table on the page. But say HTTP 404 - /SendRedirect/search not found.

SendRedirect is the mainproject
search is mapping the servlet ....... right?

I wonder if the error is here
____________________________________________
<form method="post" name="frm" action="search">
_____________________________________________

Can anyone help me , please

thanks


Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Is your servlet in a package? If not, then it should be. Start by fixing that.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60741
    
  65

Also, your action value needs to be the server-relatice URL of the servlet that the form is to be submitted to, starting with the context path of the application.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Alen Mester
Greenhorn

Joined: Jul 08, 2011
Posts: 21
OK.

Thanks for the help


First my servlet was in a default package so now is in a name package called "Servlet"

Second the path of the aplication in my action value is like this.....

"<form method="post" name="frm" action="SendRedirect/Servlet/search">" or How is?

SendRedirect ----name of principal project
Servlet------- name of package where is the servlet

Also in the XML what changes of the tips you two give me.





Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60741
    
  65

Alen Mester wrote:First my servlet was in a default package so now is in a name package called "Servlet"

A poor choice. Firstly, package names should be all lowercase by convention. Secondly, "servlet" doesn't really say anything really. Try to use more descriptive package names (and which should follow the URI convention).

With regards to the action, is "SendRedirect" the context path of the application? If so, then the context path is "/SendRedirect" with a leading slash. Anything without a leading slash is page-relative and almost guaranteed to cause problems.

You should also obtain the context path programmatically from the request and not hard-code it anywhere.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

The server looks through your <servlet-mapping> elements until it finds one with <url-pattern> matching "/search". This gives it a servlet name of "SendRedirect". It then looks through your <servlet> elements until it finds one with <servlet-name> matching "SendRedirect". This tells it what the class of the servlet is; this should be "Servlet.Search".

The URL in your form should be the name of the application followed by the url-pattern in that previous paragraph. You don't specify the servlet's class name here, you specify a url-pattern and let the server resolve that to the class's name as I described.
Alen Mester
Greenhorn

Joined: Jul 08, 2011
Posts: 21
Please dont kill me

I somehow undersand the tips but it still dont work the program


the package name in lowercase ready set and go called "servlet" with the servlet class inside name "Search.java". I know is poor name but it will change after the project is working.

the action name :

Option A) action="/SendRedirect/servlet.search">
Option B) action="/SendRedirect/servlet/search">
Option C) action="/servlet.search">
Option D) action="/servlet/search">

I am reading yours post one and one more time to get it

thanks for the help







Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Review all of your <url-pattern> elements. Which of them contain the word "servlet"?
Alen Mester
Greenhorn

Joined: Jul 08, 2011
Posts: 21
Hello and thanks

Ok.

I dont see any so I have to put the servlet is , right?



<servlet-mapping>
<servlet-name>SendRedirect</servlet-name>
<url-pattern>/servlet/search</url-pattern>
</servlet-mapping>


And in the action would be

action="/SendRedirect/servlet.Search


Correct or I'm still wrong.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60741
    
  65

No. If none of your url mappings contains the word "servlet", why do you insist on putting it in your URL? Why not just use the word "flower"? or "puppy"? or "bicycle"?
Alen Mester
Greenhorn

Joined: Jul 08, 2011
Posts: 21
OK.

Here I go again, this time I did some research...

first in xml






the servlet class is where the servlet is located and the servlet mapping is "search" equal in

<form method="post" name="frm" action="search">

other way is:

<form action=http://localhost:8080/SendRedirect.Search method=POST>

I'm still missing
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60741
    
  65

Alen Mester wrote:<form action=http://localhost:8080/SendRedirect.Search method=POST>

First of all, lose the entire http://localhost:8080 part. Think about it for more than one second. What happens when you move this somewhere else or to another port?

Secondly, do not hardcode the context path. Use either <c:url> to create the url, or grab the context path with ${pageContext.request.contextPath}.

And finally, look, yes look, really look at your servlet mapping:
Why is even there if you are going to ignore it?

Now compare that mapping to your path: /SendRedirect.Search.
Do they look even close to matching? What's with the "."? What's with the capitalization of Seach?
Alen Mester
Greenhorn

Joined: Jul 08, 2011
Posts: 21
I' m here again

to say I'm sorry. In the program I'm on it, was an error on my own. two web.xml were created of nowhere that did the error. Also I will take the tips you give me and to be more careful the next time.

the extension ".do" help me as well. But I have a last question for this topic. this ".do" that works on jsp(web) and sruts projects is the easy way or the right way to develop web projets and any diferents??


thanks

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60741
    
  65

In my opinion, the .do "extension" was always a silly convention. Today, it is even more so where RESTful URLs are more of the modern practice.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Servlet and XML result HTTP 404
 
Similar Threads
Problems when viewing specific description when search
Unable to find specific product
JSP not picking up getAttribute from Servlet
JSP two pages
page gets hang on runtime