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

What's Going Wrong Here?

 
Ranch Hand
Posts: 483
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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??
 
Bartender
Posts: 4109
72
Hibernate Fedora Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ?
 
Ranch Hand
Posts: 689
Scala Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Can you please make some small change from

to



and check..
 
Nishan Patel
Ranch Hand
Posts: 689
Scala Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

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

please read this ............ Use Code Tag
 
Somnath Mallick
Ranch Hand
Posts: 483
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
^^ 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!
DirectoryStructure.jpeg
[Thumbnail for DirectoryStructure.jpeg]
Directory Structure
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Somnath Mallick wrote:



and your url-pattern of servlet-mapping is



is this helps you ? got the problem ?

 
Nishan Patel
Ranch Hand
Posts: 689
Scala Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 483
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried with :




Both of them didn't work!
 
Nishan Patel
Ranch Hand
Posts: 689
Scala Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 483
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 689
Scala Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...
 
Sheriff
Posts: 9692
42
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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

 
Somnath Mallick
Ranch Hand
Posts: 483
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 689
Scala Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
    Posts: 9692
    42
    Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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
    Posts: 483
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Thanks all for your replies! It was of great help!!
     
    Stop it! You're embarassing me! And you are embarrassing this tiny ad!
    Free, earth friendly heat - from the CodeRanch trailboss
    https://www.kickstarter.com/projects/paulwheaton/free-heat
    reply
      Bookmark Topic Watch Topic
    • New Topic