• 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
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Servlet and XML result HTTP 404

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


 
Marshal
Posts: 28293
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is your servlet in a package? If not, then it should be. Start by fixing that.
 
Sheriff
Posts: 67750
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
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.
 
Alen Mester
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 67750
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

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
Marshal
Posts: 28293
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Marshal
Posts: 28293
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Review all of your <url-pattern> elements. Which of them contain the word "servlet"?
 
Alen Mester
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 67750
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
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
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 67750
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

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
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 67750
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
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.
 
Yeah. What he said. Totally. Wait. What? Sorry, I was looking at this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic