• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Using JSTL instead of scriplets

 
Isaac Ferguson
Ranch Hand
Posts: 922
2
Java Netbeans IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am using a request like this:



in my class.

After that I am using code like this in my .jsp



in order to see the value but I don't want use scriptlets.

From my jsp when I use a tag like:


it doesn't works also I have thougth in using something like



But the tag <c:get doesn't exists.

In conclusion I don't want using scriptlets in the view.

Any idea, please?

Thanks,
 
Paul Clapham
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Angus Ferguson wrote:From my jsp when I use a tag like:


it doesn't works


Well, no, you wouldn't find that attribute in the page context because you made it a request attribute, not a page context attribute. You would access it in JSTL like this:


 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65216
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
${CVvalue3}

No pageContext prefix.
 
Stefan Evans
Bartender
Posts: 1784
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or if you want to use a prefix: ${requestScope.CVvalue}

EL provides implicit variables to pageScope, requestScope, sessionScope and applicationScope which are effectively maps into each of the attribute spaces.

 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65216
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Note: pageScope, not pageContext.

The pageContext built-in variable is a reference to the PageContext instance, not the page scope.
 
Paul Clapham
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stefan Evans wrote:Or if you want to use a prefix: ${requestScope.CVvalue}

EL provides implicit variables to pageScope, requestScope, sessionScope and applicationScope which are effectively maps into each of the attribute spaces.


And contrariwise, if you don't prefix your attribute name with any of those prefixes, then the evaluation process will look in each of those spaces in turn until it finds a suitable attribute. If it doesn't find one in any of them, then it will fail with an error message. As for which order the process considers that list of spaces, um, it does something reasonable but I don't remember what. That's because I normally don't get into the situation where I have attributes of the same name in different contexts.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65216
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:As for which order the process considers that list of spaces, um, it does something reasonable but I don't remember what.


page ⇒ request ⇒ session ⇒ application
 
Paul Clapham
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, that's actually what I would have guessed based on my understanding of "reasonable".
 
Isaac Ferguson
Ranch Hand
Posts: 922
2
Java Netbeans IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks it is working now.

Now I need use JSTL with a condition like this:

if is not null)then display this:



I don't want use scriplets.

Any idea, please?

Thanks
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65216
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use the <c:if> action and the empty operator.
 
Isaac Ferguson
Ranch Hand
Posts: 922
2
Java Netbeans IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks,

And in order to get <c:out value="${page.pageName}"/> but instead of see the value in the jsp see it in the console?

Thanks

 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65216
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no action in JSTL to emit messages to the logs. You'd need to find a 3rd party custom tag to do so, or write your own.
 
Alok Agrawal
Greenhorn
Posts: 14
Java jQuery
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can use the following code for applying condition without using scriptlets:



Please let me know for any further clarifications needed.
 
Isaac Ferguson
Ranch Hand
Posts: 922
2
Java Netbeans IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need use the "or" like this




Any idea?

Thanks
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65216
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What does the EL specification have to say about or operators?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic