• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to declare and use variables in JSTL ?  RSS feed

 
Sankar B
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear All,
How to declare variables and use it in JSTL as we do in a JSP page.
Example:
String x="test.jsp";
How to declare like this in JSTL or How to use this value of 'x' in JSTL ?
Yours,
Sankar.B
Information Dynamics, Chennai, India
 
Shawn Bayern
Author
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use <c:set> to set a scoped variable and <% pageContext.setAttribute("x", x) %> to convert a scripting variable into a scoped variable.
 
Sankar B
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
For lot of simpler calculations and validations using Javascript we used to declare variables and then do them and use it in Javascript before submitting a form.
Say, int x=2,y=3;x=x+y; and use it in the form as a default value and then we may validate the user input from Javascript and then post the form date using Javascript itself. For these situations, we need to use Java code for declaring and calculations.
How to use the above declared value without making it as a scoped variable ?
Yours,
Sankar.B
 
Shawn Bayern
Author
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm sorry; I don't understand your question.
If you're asking how to get the JSTL expression language to use a scripting variable, the answer is that it's structurally impossible. You must turn it into a scoped attribute.
If you're asking about some more complicated relationship between JavaScript data and its posting to a JSP page, I'm afraid you haven't supplied enough information.
Hope that helps,
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!