Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JSP tags (JSTL) and request Attributes  RSS feed

 
matias casal
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello.

I am starting with tags, and I have the following doubt.

I have an strut action where I send this request attribute



Now, I would like to know how can I use this attribute from jsp or from a tag handler class

I tried pageContext.getAttribute("object") but I think it returns null.

Thank you
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65826
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Within a JSP page, you'd use the following EL expression: ${object}

matias casal wrote:... from a tag handler class ... I tried pageContext.getAttribute("object") but I think it returns null.


Why would you look in page scope for a scoped variable that you placed in request scope?

 
matias casal
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But if i want to use this ${object} in a java class, how can I do?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65826
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You already know about getAttribute(), so what's the problem? Just be sure to use it on the correct scope.

Looking for a scoped variable that you placed in request scope within page scope is like putting your jacket in the hall closet and then wondering why you can't find it in the pantry.
 
matias casal
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My problem is that, i send the attribute from an strut action


Then the strut actions goes to queyr.jsp

From query.jsp if i do something like this with scriptless

works perfectly

But now, I trying to use jsp tags.
In my tag handler i have the following code

or this


But when I use those in the tag handler the jsp is not load beause of
HTTP 500
org.apache.jasper.JasperException: javax.servlet.ServletException: javax.servlet.jsp.JspException: null
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:522)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:398)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.apache.struts.chain.commands.servlet.PerformForward.handleAsForward(PerformForward.java:113)
org.apache.struts.chain.commands.servlet.PerformForward.perform(PerformForward.java:96)
org.apache.struts.chain.commands.AbstractPerformForward.execute(AbstractPerformForward.java:54)
org.apache.struts.chain.commands.ActionCommandBase.execute(ActionCommandBase.java:51)
org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.java:304)
org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:283)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462)
javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

Any suggestion ?



 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65826
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I will repeat for the 3rd time: if you put a scoped variable in request context you must get it from request context.
 
matias casal
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I understood what you say.
But I have NO IDEA of how to do it in the tag handler.
Sorry for being reiterative
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65826
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Get the request from the page context, find the scoped variable within it.
 
matias casal
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Get the request from the page context, find the scoped variable within it.


Is it ok?, Whats the problem with this code?



It throws a null exception.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65826
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is that whole statement?

 
Satya Sakhinetipalli
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use findAttribute method in PageContext if you are not sure of the scope of the variable:

 
matias casal
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried with



And null exception
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65826
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So what have you done to find out what's null? Have you verified that pageContext is not null? ShowSomeEffort!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!