This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem with "jsp:useBean" tag

 
J Lalit
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

i have two jsp,first is the one from where i am submitting data & second where i am showing data using <jsp:useBean> tag but getting null on second jsp.My jsps are as below.

----------index.jsp-----------

<body>
<form name="myForm" method="post" action="showData.jsp">
<jsp:useBean id="show" class="com.test.ShowBean" scope="session"/>
<jsp:setProperty name="show" property="*"/>
<table>
<tr>
<td>
Enter Your Name :
<input type="text" name="name"/>
</td>
</tr>
<tr>
<td>
Enter Your Mobile :
<input type="text" name="mobile"/>
</td>
</tr>
<tr>
<td>
<input type="submit" value="Submit"/>
</td>
</tr>
</table>
</form>
</body>

From here i am submitting request to showData.jsp which is as

-----------showData.jsp-----------

<body>
<jsp:useBean id="show" class="com.test.ShowBean" scope="session"/>
Name is : <jsp:getProperty name="show" property="name"/><br>
Mobile is : <jsp:getProperty name="show" property="mobile"/><br>
</body>

But i am getting values of name & mobile as null.

Can anyone tell me where it is going wrong.

Also can i use <jsp:useBean> to submit data to a servlet & show data there as also in that case i am getting null values.

Thanks in Advance.
 
tong yuxin
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi, i think (not sure) ths index.jsp has some problem

<jsp:setProperty name="show" property="*"/>
==
<jsp:setProperty name="show" property="name" param="name">
<jsp:setProperty name="show" property="moblie" param="mobile">

So, before index.jsp sent the request, it cannot get the paramvalue at that time.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by tong yuxin:
So, before index.jsp sent the request, it cannot get the paramvalue at that time.


Exactly...

----------------------------------------------------------
i think (not sure) ths index.jsp has some problem

<jsp:setProperty name="show" property="*"/>
==
<jsp:setProperty name="show" property="name" param="name">
<jsp:setProperty name="show" property="moblie" param="mobile">
-------------------------------------------------------

Not a problem if form field name and setter method name(bean method) same
 
Marimuthu Madasamy
Ranch Hand
Posts: 72
Java Monad Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are two request objects involved. First one is to render index.jsp and the second one is to render showData.jsp (after you submit the form in index.jsp). your jsp:setProperty in index.jsp retrieves the parameters (actually there is none) from the first request and sets the properties. When you submit the form, now the new request (to showData.jsp) with the submitted data is sent but you didnt use the jsp:setProperty in showData.jsp. so

have this line in showData.jsp after jsp:useBean,
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic