This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JSP and the fly likes Using JSTL instead of scriplets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Using JSTL instead of scriplets" Watch "Using JSTL instead of scriplets" New topic
Author

Using JSTL instead of scriplets

Isaac Ferguson
Ranch Hand

Joined: Jun 22, 2012
Posts: 331
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
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

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

Joined: Jan 10, 2002
Posts: 60763
    
  65

${CVvalue3}

No pageContext prefix.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Stefan Evans
Bartender

Joined: Jul 06, 2005
Posts: 1016
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

Joined: Jan 10, 2002
Posts: 60763
    
  65

Note: pageScope, not pageContext.

The pageContext built-in variable is a reference to the PageContext instance, not the page scope.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

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

Joined: Jan 10, 2002
Posts: 60763
    
  65

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
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Yes, that's actually what I would have guessed based on my understanding of "reasonable".
Isaac Ferguson
Ranch Hand

Joined: Jun 22, 2012
Posts: 331
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

Joined: Jan 10, 2002
Posts: 60763
    
  65

Use the <c:if> action and the empty operator.
Isaac Ferguson
Ranch Hand

Joined: Jun 22, 2012
Posts: 331
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

Joined: Jan 10, 2002
Posts: 60763
    
  65

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

Joined: Feb 01, 2008
Posts: 12

you can use the following code for applying condition without using scriptlets:



Please let me know for any further clarifications needed.

Alok Agrawal
Learn Thru PPT Sports Info
Isaac Ferguson
Ranch Hand

Joined: Jun 22, 2012
Posts: 331
I need use the "or" like this




Any idea?

Thanks
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60763
    
  65

What does the EL specification have to say about or operators?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Using JSTL instead of scriplets
 
Similar Threads
Displaying Data From Different Tables in .jsp
Accessing a variable declared in JSTL in jsp
How to identify a particular selected record in struts?
Getting a Request object from a Handler in JSPs
Passing row id from html table on jsp to Action Class in Struts