Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

config Implicit Variable - Major Doubt

 
Sandeep Vaid
Ranch Hand
Posts: 392
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In Hanumant deshmukh's book [p-205]



initTest.jsp File :




Now it says that :
When JSP page initTest.jsp is accessed as a servlet, using the http://localhost:8080/chapter11/servlet/InitTestServlet it will work fine.

Ques 1: How can you access using Servet-Name?
Ques 2 : when i define proper servlet-mapping, then i can access it using url-pattern but when i print all the init ariables (not in above code) the output comes as :
fork : false xpoweredBy : false <Now proper init varaibles > ?
Why extra parms : fork and xpoweredBy ?
 
Joe Harry
Ranch Hand
Posts: 10105
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you try it actually?? It should have given you a 404...when you try to access using the servlet name instead of the url pattern...
 
Stein Vom
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can a servlet directly without url-pattern with

urWebApp/servlet/servletName
 
Joe Harry
Ranch Hand
Posts: 10105
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stein...are you sure?? I tried this and gave me 404...
 
Joe Harry
Ranch Hand
Posts: 10105
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm using a form action...I got my mistake...yes, you can access the servlet with its name...You are right stein...
 
Stein Vom
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
tell me the exact URL that you are typing and also your servlet file name
 
Stein Vom
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok. . .great
 
Sergio Tridente
Ranch Hand
Posts: 329
Java Linux Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Stein Vom:
You can a servlet directly without url-pattern with

urWebApp/servlet/servletName


Can you point out where did you get this from? Is it in the spces?

I am asking because in the exam we won't be tested on tomcat but on what the spec says.
 
Darren Weaver
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As for Question 1., in the DD of the particular example you posted, there is an explicit servlet-mapping which happens to match the name of the servlet (prepended with the path /servlet).
 
Rancy Chadha
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sandeep,

Darren is right. In your DD you have this:
<servlet-mapping><servlet-name>InitTestServlet</servlet-name><url-pattern>/servlet/InitTestServlet</url-pattern> </servlet-mapping>


and you are using link <a href="http://localhost:8080/chapter11/<i rel="nofollow">servlet/InitTestServlet</i>" target="_blank">http://localhost:8080/chapter11/servlet/InitTestServlet to invoke the JSP. Thus you are not accessing your JSP with the value of <servlet-name> but with the name in <url-pattern>.

Thanks,
-Rancy
 
Sandeep Vaid
Ranch Hand
Posts: 392
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what i am trying to say is :

Suppose i have only defined <servlet> element in web.xml & not <servlet-mapping> as in :


then according to the book, i can access my JSP using :
http://localhost:8080/<web-app name>/InitTestServlet

Note: this is not working. Moreover how can i use a servlet-name to access JSP/servlet ?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic