Only 48 hours left in the trailboss' kickstarter!

New rewards and stretch goals. CLICK HERE!



  • Post Reply Bookmark Topic Watch Topic
  • New Topic

jsp and java beans  RSS feed

 
hari vallabh shukla
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 65824
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why aren't you using the JSTL and EL? getProperty and setProperty are obsolete.
 
Stefan Evans
Bartender
Posts: 1834
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what "same" code do you write in scriptlet?
If its not giving the same result, it can't be the same :-)

 
hari vallabh shukla
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 65824
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 vallabh shukla
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!