• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

portlet jsp code puzzle

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

Anybody tell me why I'm getting "null" value for the following? Interesting puzzle! code compiles and runs but with null values.

Thanks in advance.
JCT




[ Jess added UBB [ code ] tags to preserve whitespace and keep things easier to read ]
[ November 22, 2005: Message edited by: Jessica Sant ]
 
Author
Posts: 121
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I do not understand the brackets behind session in the JSP, in line

The implicit page object "session" is available without brackets. Does this call do something else?
[ November 23, 2005: Message edited by: Stefan Zoerner ]
 
jeff thompson
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Stephan,

That's just a typo. See the cut down version below!

Let me switch to what I've been doing to what I'd like to do with this portlet is as follows.

1) User logs in and sees portlet that displays a link.
2) User clicks on link to name.jsp
3) name.jsp is executed and then redirects the user to a remote application

The reason I think I'm getting null/NPE is because when the link is clicked the sesion information is lost- I may be wrong but I don't have any other explanation for this. I really don't care to have this particular link. Any link (even fake one) would be fine. The behaviour that I want is for the portlet to present some link the first time it's rendered and upon clicking this link the user attributes (name, passwd) could be passed to the remote application that would then open in its own browser window.

=====================================================================
protected void doView(RenderRequest request, RenderResponse response)
throws PortletException, IOException
{

String username="Jeff";

PortletSession session=request.getPortletSession();
session.setAttribute("username", username, PortletSession.APPLICATION_SCOPE);
request.setAttribute("username", username);
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<table border=\"0\" width=\"100%\">");
out.println("<tr>");
out.println("<td>");
//provide clickable link for the user
out.println("<a resource window\" href=http://mail.yahoo.com/config/login?/\"" +
request.getContextPath() + "/jsp/name.jsp" + "\">click here</a>");
out.println("</td>");
out.println("</tr>");
out.println("</table>");

PortletContext portletContext = getPortletContext();

PortletRequestDispatcher prd = portletContext.getRequestDispatcher("/jsp/name.jsp");
prd.include(request, response);
}


code:


//name.jsp file

<%@ page import="javax.portlet.RenderRequest" %>
<%@ page import="javax.portlet.RenderResponse" %>
<%@ page import="javax.portlet.PortletPreferences" %>
<%@ page import="javax.portlet.PortletSession" %>
<%@ taglib uri="http://java.sun.com/portlet" prefix="portlet" %>

<!--%@ page session="false" %-->
<portlet efineObjects/>

//puzzle value of username null- why?
<% String name =(String)session.getAttribute("username"); %>
<%= name %>

<% String uname=(String)request.getAttribute("username"); %>
<%= uname %>
 
Ranch Hand
Posts: 375
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The session information is not being lost.

You are currently retrieving a normal servlet session from within your JSP, so you cannot find the username attribute within it.

Use "renderRequest.getPortletSession().getAttribute("username")" to retrieve portlet sessions. Objects "request" and "session" do not refer to portlets.
 
Forget this weirdo. You guys wanna see something really neat? I just have to take off my shoe .... (hint: it's a tiny ad)
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic