• Post Reply Bookmark Topic Watch Topic
  • New Topic

portlet jsp code puzzle

jeff thompson
Posts: 2
  • Mark post as helpful
  • send pies
  • 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.

[ Jess added UBB [ code ] tags to preserve whitespace and keep things easier to read ]
[ November 22, 2005: Message edited by: Jessica Sant ]
Stefan Zoerner
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • 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
Posts: 2
  • Mark post as helpful
  • send pies
  • 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);
PrintWriter out = response.getWriter();
out.println("<table border=\"0\" width=\"100%\">");
//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>");

PortletContext portletContext = getPortletContext();

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


//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 %>
K Riaz
Ranch Hand
Posts: 375
  • Mark post as helpful
  • send pies
  • 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.
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!