• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

adding a servlet

 
abhay jain
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have deployed a servlet a servlet and run it in browser success fully
then i added an html form and it also added successfully
then i tried to connect it with a servlet that should receive data sent by previously added html form

but on clicking submit button this error comes every time
--------------------------------------------------------------------------------------
HTTP Status 404 - /roota/Myname

type Status report

message /roota/Myname

description The requested resource (/roota/Myname) is not available.
-----------------------------------------------------------------------------------------


here is that receiver servlet code




that html file.....




and now web.xml file ......







 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64717
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your form action should be server-relative beginning with the context path and then followed by the servlet mapping.
 
abhay jain
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your form action should be server-relative beginning with the context path and then followed by the servlet mapping.



i m new with this .....please explain this with an easy example .. if possible
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64717
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
action="/contextpath/servletpath"
 
Lalit Jugran
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi abhay jain,

make following changes to your program

1- in html replace <form method ="get" action="Myname"> with <form method ="get" action="ala">
2- in web.xml replace <servlet-class>Welcomserv</servlet-class> with <servlet-class>Myname </servlet-class>

hope your program will run correctly.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64717
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lalit Jugran wrote:make following changes to your program .... action="ala"

No. No. No. No. No.

Use the format of the action I advised. Anything else is folly.

 
abhay jain
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sure..... but actually i m still confuse with terms "context path" and "servlet path"


here is the location of files in my PC

source code files are at this path ........


D:\project [no sub directies used]

and files after deployment are at this path ......

D:\Sun\AppServer\domains\domain1\applications\j2ee-modules\wara


wara directory contains contains META-INF, WEB-INF, welcomehtm.html



please help me in creating servletpath and contextpath
 
Ashwin Sridhar
Ranch Hand
Posts: 277
Flex Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess this was the issue with one of your previous posts as well.

your previous post

Here, from your post, your action name and url pattern doesn't match. same was the problem you mentioned in previous posts as well.
 
abhay jain
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have tried as you said my friend but unable to achieve any positive result (it may be my mistake in implementation of idea you gave ) but here is the current situation ..please give your opinion on this

html file ......




web.xml file .........


 
Lalit Jugran
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi abhay jain

make changes what I posted in earlier postes. If your program still shows error message, post your folder structures of jsp & classes inside webapps folder.
 
Ashutosh Limaye
Ranch Hand
Posts: 58
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
abhay jain wrote:i have deployed a servlet a servlet and run it in browser success fully
then i added an html form and it also added successfully
then i tried to connect it with a servlet that should receive data sent by previously added html form

but on clicking submit button this error comes every time
--------------------------------------------------------------------------------------
HTTP Status 404 - /roota/Myname

type Status report

message /roota/Myname

description The requested resource (/roota/Myname) is not available.
-----------------------------------------------------------------------------------------


here is that receiver servlet code




that html file.....




and now web.xml file ......






Points to Remember regarding Servlets:

1. Servlets (.class) files should always be in a package. That is a undocumented requirement of a dynamic web application .
2. the action attribute of the form tag should always contain the url-pattern you mention in the web.xml. ala in your case.
3. The <servlet-class> tag should have the fully qualified name of your .class file which should be in classes folder.
<servlet-class>[some packagename].Myname</servlet-class>
do the following changes and your problem should get solved. Remember most of the time 404 errors come because of wrong/error-prone web.xml.
 
Ashwin Sridhar
Ranch Hand
Posts: 277
Flex Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Had you made your Action name in html file to be same as url-pattern (case-sensitive), then your problem is solved.

if not, tell more about your folder structure
 
abhay jain
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ashutosh Limaye , Ashwin Sridhar, Lalit Jugran

thanks a lot friends

i have implemented as you all instructed
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64717
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The context path is the route to the web application. You can obtain it from the request. All URLs for actions or resource like images or script files should start with the context path.

The servlet path is the mapping that you assigned to the servlet in the deployment descriptor.

These are essential concepts for you to understand, and forming URLs any other way is going to be fragile and error-prone.
 
abhay jain
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, you specifically left me off the list of people whose ideas you implemented.


the only problem is that i am new with Servlet concept, i have never used it in any way..that's why sometimes it takes too much time to implement a simple + effective idea... hope you understand ... no one would like to miss your precious opinion
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64717
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As someone new to the concepts it's important to learn the best practice ways of doing things. Just getting things to work isn't good enough, and taking shortcuts at the outsert just instills bad habits that are hard to break later.

I'm glad you want to do things the correct way.

In a JSP, another way to make sure that your URLs are correctly formed is to use the <c:url> JSTL tag to create the urls.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic