• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jstl c:url tag doubt ?

 
gurpeet singh
Ranch Hand
Posts: 924
1
Fedora Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
following is a question from enthuware ocewcd 6 mock exam ?

Which of the following code correctly performs URL rewriting ?

1.) <a href="<c:url value='/cart.jsp?userid='ramesh'/>">View Cart</a>

2.) <a href="<c:url value='/cart.jsp' userid='ramesh'/>">View Cart</a>

3.) <a href="<c:url value='/cart.jsp' attr='userid' value='ramesh'/>">View Cart</a>

4.)<a href="<c:url value='/cart.jsp'>
<c:param name='userid' value='ramesh'/>
</c:url>">View Cart</a


the correct answer is option 4. why is the first option NOT correct?

can't we pass request parameters directly in the value attribute of c:url tag ? is it mandatory to use c:param tag jstl tag?


p.s. - i have posted this question in the enthuware forum also so that i can get a quick reply since i have my D-day for the exam tomorrow. i have searched google but couldnt find any answer

thanks and regards
Gurpreet
 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Pie
Posts: 2536
113
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Gurpeet,

I am not sure whether you typed it over correctly but I would say in the first option there is a quotation mark ( ' ) too much at the beginning of ramesh

Regards,
Frits
 
gurpeet singh
Ranch Hand
Posts: 924
1
Fedora Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Frits Walraven wrote:Hi Gurpeet,

I am not sure whether you typed it over correctly but I would say in the first option there is a quotation mark ( ' ) too much at the beginning of ramesh

Regards,
Frits


i checked the question and yes there is a ( ' ) at the beginning of ramesh. i think it is a typo. lets remove it. will then it be a correct answer ??

want to know that do we need c:param to pass request parameters ? is it mandatory ?
 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Pie
Posts: 2536
113
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
lets remove it. will then it be a correct answer ??

Yes, then it will be ok

from the jstl specs

Syntax 1: Without body content
<c:url value="value" [context="context"][var="varName"] [scope="{page|request|session|application}"]/>

Syntax 2: With body content to specify query string parameters
<c:url value="value" [context="context"][var="varName"] [scope="{page|request|session|application}"]>
<c:param> subtags
</c:url>


p.s. - i have posted this question in the enthuware forum also so that i can get a quick reply since i have my D-day for the exam tomorrow. i have searched google but couldnt find any answer

p.s. Good luck tomorrow!

Regards,
Frits
 
gurpeet singh
Ranch Hand
Posts: 924
1
Fedora Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Fritz
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic