• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Using <c:set target>

 
Satyajeet Kadam
Ranch Hand
Posts: 224
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have some dout in understanding <c:set target> with beans
Please correct me if i am wrong

Q1) Before using <c:set target> is it necessary to use <jsp:useBean> or there is another way for it?
Q2) From my below source code i found that value of the id in <jsp:useBean> must match with value of the target in <c:set>? is it correct?



Q3) Please find the complete source code for the same.


Car.java



Result.jsp


 
Ankit Garg
Sheriff
Posts: 9577
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Q1) Before using <c:set target> is it necessary to use <jsp:useBean> or there is another way for it?


It is not necessary to use <jsp:useBean> with <c:set target>, the target element must point to an object i.e. an attribute in any scope. So if there is an object named me in request scope, then I can use the following code without any useBean tag

 
Bindu Lakhanpal
Ranch Hand
Posts: 171
Flex Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In your example <jsp:useBean is creating a new attribute called car1 which is representing the newly created bean car.
${car1} is the bean ( object).

You could have declared a bean in a servlet like folowing before forwarding it to your jsp.

Now in jsp you don't need to create a new bean using ><jsp:useBean action.


The target should be an object and not any attribute set in a scope.We can't have ><c:set target="stringvalue" ... where "stringvalue" is an attribute. But we can have target="${stringvalue"} if strinvalue is an attribute representing a bean (or map)
Target needs a value that should evaluate to a real object.It means target value can be EL expression or a scripting expression or ><jsp:attribute> but can't be a string which represents the name under which an attribute was bound.


Ankit Garg wrote:<c:set target="requestScope.me" property="..." value="..." />


you mean
 
Ankit Garg
Sheriff
Posts: 9577
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bindu Lakhanpal wrote:
Ankit Garg wrote:<c:set target="requestScope.me" property="..." value="..." />


you mean


Yes I forgot the EL in it
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic