This week's book giveaway is in the Spring forum.
We're giving away four copies of Spring Boot in Practice and have Somnath Musib on-line!
See this thread for details.
Win a copy of Spring Boot in Practice this week in the Spring forum!
  • 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
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

problem with "jsp:useBean" tag

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 72
Scala Monad Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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,
reply
    Bookmark Topic Watch Topic
  • New Topic