GeeCON Prague 2014*
The moose likes Servlets and the fly likes What's Going Wrong Here? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Servlets
Bookmark "What Watch "What New topic
Author

What's Going Wrong Here?

Somnath Mallick
Ranch Hand

Joined: Mar 04, 2009
Posts: 477
HI Everyone,

I ahve written a servlet code. But somehow I am running into problems! The basic flow is from a JSP --> Servlet --> JSP. But somehow my context path has gone wrong somewhere.

My form tag consists of this:

My web.xml:
[/code]

But somehow the context name which turns up is:


Could you please tell me where i am going wrong??
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3833

How is your application deployed (directory structure) ? Are you able to access any other resource(s) in the application & how you access (i.e. URL) the resource ?


SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
Nishan Patel
Ranch Hand

Joined: Sep 07, 2008
Posts: 688

Hi,

Can you please make some small change from

to



and check..


Thanks, Nishan Patel
SCJP 1.5, SCWCD 1.5, OCPJWSD Java Developer,My Blog
Nishan Patel
Ranch Hand

Joined: Sep 07, 2008
Posts: 688

Hi,

Use [code] tag when you question at java ranch with code...

please read this ............ Use Code Tag
Somnath Mallick
Ranch Hand

Joined: Mar 04, 2009
Posts: 477
^^ That didn't work!

I have attached my directory structure please check it out.

I did use code tag! Somehow got removed when i was editing my post!



[Thumbnail for DirectoryStructure.jpeg]

Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Somnath Mallick wrote:



and your url-pattern of servlet-mapping is



is this helps you ? got the problem ?

Nishan Patel
Ranch Hand

Joined: Sep 07, 2008
Posts: 688

Hi,

It's my mistake change


to



from the <url-pattern> your servlet selected .... so just change this and check for problem ...
Somnath Mallick
Ranch Hand

Joined: Mar 04, 2009
Posts: 477
I tried with :




Both of them didn't work!
Nishan Patel
Ranch Hand

Joined: Sep 07, 2008
Posts: 688

Hi,

After make changes to <form action="/iVVTPortal2/EnvDetailsServlet" method="post">

still show the message,


HTTP Status 404 - /iVVTPortal2/jsp/EnvDetailsServlet
type Status report

message /iVVTPortal2/jsp/EnvDetailsServlet

description The requested resource (/iVVTPortal2/jsp/EnvDetailsServlet) is not available.
Apache Tomcat/6.0.20


Can you please post your code from where you dispatch to your jsp page using JSP --> Servlet --> JSP

If you are using Servlet then your code looks like this into servlet,



Somnath Mallick
Ranch Hand

Joined: Mar 04, 2009
Posts: 477
Atleast that extra "jsp" has gone away from the context path. Now i get the error:


My JSP Page is:


This sends the request from JSP-->Servlet. This is in the jsp folder of the WebContent.
Nishan Patel
Ranch Hand

Joined: Sep 07, 2008
Posts: 688

Hi,

/jsp/yourJsp .jsp this path depending upon your application structure. It you put your jsp file at context level then it simply required /yourjsp.jsp...
I just give you simple example...
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9303
    
  17

Somnath please Use A Meaningful Subject Line when you start a topic.

Did you change the URL patter

to


in your deployment descriptor?? Also in your JSP you don't need to hard code the context path. You can use ${pageContext.request.contextPath} like



SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Somnath Mallick
Ranch Hand

Joined: Mar 04, 2009
Posts: 477
Thanks Ankit, your suggestion worked. Could you please explain me what this statement does: pageContext.request.contextPath? Also one of my friends told me to use:

Its also working! Could you please tell me how?
Nishan Patel
Ranch Hand

Joined: Sep 07, 2008
Posts: 688

pageContext is of type javax.servlet.jsp.PageContext.

pageContext class is an abstract class.

It do following things

  • provide convenience methods to get and set attributes in diff scopes.


  • provide convenience methods for transferring requests to other resources in the web application


  • store the references to implicit objects


  • when you write pageContext.request.contextPath will give you request object and get path to your project like localhost:8080/Test

    so
    form action="${pageContext.request.contextPath}/EnvDetailsServlet" method="post">


    this will make post on action localhost:8080/Test/EnvDetailsServlet

    Ankit Garg
    Sheriff

    Joined: Aug 03, 2008
    Posts: 9303
        
      17

    Somnath, Nishan explained everything nicely. As far as using ../ is concerned, it worked fine in this case. But its not necessary that it will work in all the cases. Using ../ is a relative path. So if your jsp is accessed using the URL


    then ../EnvDetailsServlet will point to


    But if your jsp is accessed using the URL then ../EnvDetailsServlet will point to
    This might be problematic. So using the complete path from the context path is the best choice...
    Somnath Mallick
    Ranch Hand

    Joined: Mar 04, 2009
    Posts: 477
    Thanks all for your replies! It was of great help!!
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: What's Going Wrong Here?