8 Replies - 78521 Views - Last Post: 11 February 2011 - 04:02 AM

#1 shadowBean  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 47
  • Joined: 14-June 08

How to receive Attribute values from servlet on JSP Page

Posted 17 June 2008 - 08:05 PM

I have a servlet that sends values to a JSP page. On my JSP I use EL ${} to display values. All works ok. But I need to assign some values to variables
heer is my simplified code

servlet
req.setAttribute("Message" , Message);
req.setAttribute("arrayApp" , arrayApp);
req.setAttribute("insertId" , insertId ); 

RequestDispatcher dispatcher = req.getRequestDispatcher("Process.jsp");
dispatcher.forward(req,res);



JSP
<table>
<tr><td>${arrayApp[0]}</td></tr>
<tr><td>
<%=  request.getAttribute(insertId)  %>
</td></tr>
</table>



I am just trying to use insertId but after trying so many different ways not successful. Not only insertId (object from database) but I can't seem to receive any values other than by using EL.

The question is what is the object I need to use to receive values?

Regarding the insertId I used toString() to convert it to String before sending it. But result is the same.

Many Thanks

Is This A Good Question/Topic? 0
  • +

Replies To: How to receive Attribute values from servlet on JSP Page

#2 1lacca  Icon User is offline

  • code.rascal
  • member icon

Reputation: 44
  • View blog
  • Posts: 3,822
  • Joined: 11-August 05

Re: How to receive Attribute values from servlet on JSP Page

Posted 18 June 2008 - 01:13 AM

<%= request.getAttribute(insertId) %>
should be
<%= request.getAttribute("insertId") %>
Was This Post Helpful? 0
  • +
  • -

#3 shadowBean  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 47
  • Joined: 14-June 08

Re: How to receive Attribute values from servlet on JSP Page

Posted 18 June 2008 - 01:36 AM

Thanks I tried that first thing. Nothing. I can only get the value from ${insertId} but not <%= request.getAttribute("insertId") %>
Don't know why.

Thanks again
Was This Post Helpful? 0
  • +
  • -

#4 1lacca  Icon User is offline

  • code.rascal
  • member icon

Reputation: 44
  • View blog
  • Posts: 3,822
  • Joined: 11-August 05

Re: How to receive Attribute values from servlet on JSP Page

Posted 18 June 2008 - 02:02 AM

Could you post the whole JSP and the part of the servlet from declaring insertId to setting it into the request?
Was This Post Helpful? 0
  • +
  • -

#5 shadowBean  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 47
  • Joined: 14-June 08

Re: How to receive Attribute values from servlet on JSP Page

Posted 22 June 2008 - 03:15 AM

I got it thanks,
silly mistake

However, How do I assign this Attribute Value to another variable

ie. String s = session.getAttribute("s") ;

when session.getAttribute() is an object how do I convert it to assign it to String or interger

Thanks again

This post has been edited by shadowBean: 22 June 2008 - 03:27 AM

Was This Post Helpful? 0
  • +
  • -

#6 1lacca  Icon User is offline

  • code.rascal
  • member icon

Reputation: 44
  • View blog
  • Posts: 3,822
  • Joined: 11-August 05

Re: How to receive Attribute values from servlet on JSP Page

Posted 23 June 2008 - 02:57 AM

You need to cast it:
String s = (String)session.getAttribute("s") ;
It'll work for null values as well, so don't forget to check them before calling methods on them (to avoid null pointer exceptions)
Was This Post Helpful? 1

#7 shadowBean  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 47
  • Joined: 14-June 08

Re: How to receive Attribute values from servlet on JSP Page

Posted 24 June 2008 - 02:00 AM

thanks,
Was This Post Helpful? 0
  • +
  • -

#8 sweetaabha  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 23-February 10

Re: How to receive Attribute values from servlet on JSP Page

Posted 23 February 2010 - 01:48 AM

View Post1lacca, on 18 June 2008 - 12:13 AM, said:

<%= request.getAttribute(insertId) %>
should be
<%= request.getAttribute("insertId") %>



Hello
This <%= request.getAttribute(insertId) %> should be this
<%= request.getAttribute("insertId") %>
Was This Post Helpful? 0
  • +
  • -

#9 Guest_Rockvel*


Reputation:

Re: How to receive Attribute values from servlet on JSP Page

Posted 11 February 2011 - 04:02 AM

In JSP we use Scriplet Tag for this program.......
Page1.JSP

<%
String trans="Pass the value to multiple page....";

session.setAttribute("get",trans);

%>

Page2.JSP
<%
String receive=(String )session.getAttribute("get");
out.println(receive);
%>
Was This Post Helpful? 0

Page 1 of 1