Get Attribute variable passed from servlet
All, I have a attribute variable set in the servlet. and want to get it in
the jsp. But I have some questions about it. Say you have the code .
In the servlet.
protected void doGet(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {
request.setAttribute("BeerSelected", "BlackBeer");
RequestDispatcher
disp=request.getRequestDispatcher("SelectResult.jsp");
disp.forward(request,response);
}
In the JSP
this code works
<%String name = (String)request.getAttribute("BeerSelected");%>
<%= name%>
But why below code doesn't work? jsp doesn't render the value .
<%request.getAttribute("BeerSelected");%>
Neither does below code.
<%request.getAttribute("BeerSelected").toString();%>
I don't know why toString() doesn't work. thannks.
No comments:
Post a Comment