Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

servlet maping

 
dharmendra Rathor
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Given that a servlet is correctly declared with the tag

<servlet>
<servlet-name>HelloWorld</servlet-name>
<servlet-class>com.examulator.HelloWorld</servlet-class>
</servlet>


Which of the following represent the correct syntax for mapping a servlet url to a servlet name

a)
<servlet-mapping>
<servlet-name>HelloWorld</servlet-name>
<url-pattern>hello</url-pattern>
</servlet-mapping>

b)
<servlet-mapping>
<servlet-name>HelloWorld</servlet-name>
<url-pattern>*.java</url-pattern>
</servlet-mapping>

c)
<servlet-mapping>
<servlet-name>HelloWorld</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>

d)
<servlet-mapping>
<servlet-name>HelloWorld</servlet-name>
<url-pattern>/com.examulator.HelloWorld</url-pattern>
</servlet-mapping>

answer is ( c , d )
Why d is also true ?
 
khushhal yadav
Ranch Hand
Posts: 242
Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Dharmendra,

How come answers are c and d?
Correct answers are b and c..

Please check it again.

Regards,
Khushhal
 
nivas ratthaaq
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
b,c,d are correct.
Option 'd' is correct because whatever you give you should add '/'(represents context root I guess) before it in ''url-pattern' tag. If you try to access like 'contextRoot/com.examulator.HelloWorld' it works.

But in the case of operator '*' I think you can give as it is with out adding any '/'. Here try give like 'contextRoot/anything.java' it works.

Regards,
nivas
 
Ken Truitt
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Isn't it the case that for url-patterns, there are 3 types:

1)exact--/aDir/anotherDir/aResource.do

2)directory--/aDir/anotherDir/*

and

3)extension--*.do

So *.java works, 'hello' would be exact but no '/' so it fails,
and so on.

Ken Truitt
 
khushhal yadav
Ranch Hand
Posts: 242
Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nivas, you are right d) is also one of the correct option, falls under second category.
Correct are b, c and d.

Regards,
Khushhal
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic