File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes jsp and java beans Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "jsp and java beans" Watch "jsp and java beans" New topic
Author

jsp and java beans

hari shukla
Greenhorn

Joined: Jan 31, 2013
Posts: 21
Below code give output NULL





<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Registration</title>
</head>
<body>


<jsp:useBean id="userBean" class="registration.UserBean" scope="session">
</jsp:useBean>

YOUR NAME :<jsp:getProperty name="userBean" property="name"/>



YOUR EMAIL:<jsp:getProperty name="userBean" property="email"/>




</body>
</html>


OUTPUT is below

YOUR NAME : NULL
YOUR EMAIL :NULL




but when i write same code in scriplet it give correct output
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60056
    
  65

Why aren't you using the JSTL and EL? getProperty and setProperty are obsolete.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Stefan Evans
Bartender

Joined: Jul 06, 2005
Posts: 1016
what "same" code do you write in scriptlet?
If its not giving the same result, it can't be the same :-)

hari shukla
Greenhorn

Joined: Jan 31, 2013
Posts: 21
Stefan Evans wrote:what "same" code do you write in scriptlet?
If its not giving the same result, it can't be the same :-)





<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Registration</title>
</head>
<body>
<% registration.UserBean userBean=(registration.UserBean)Session.getAttribute("userBeanString"); %>

YOUR NAME : <%= userBean.getName()%>


YOUR EMAIL:<%= userBean.getEmail()%>


</body>
</html>


OUTPUT IS BELOW

YOUR NAME : CORRECT NAME
YOUR EMAIL :CORRECT EMAIL
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60056
    
  65

The EL for <%= userBean.getName()%> would be ${userBeanString.name}.

The EL and JSTL have been around for about 12 years. Is it not time to start using them?
hari shukla
Greenhorn

Joined: Jan 31, 2013
Posts: 21
Bear Bibeault wrote:The EL for <%= userBean.getName()%> would be ${userBeanString.name}.

The EL and JSTL have been around for about 12 years. Is it not time to start using them?



Thanks iam using EL and it working fine
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: jsp and java beans
 
Similar Threads
use of value object ( javabeans )
jsp second request also make new object
retrive serialize files data ERROR
How to create scrolling text?
Help:jsp pass message to Beans, but always receive null