Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jsp:useBean Example

 
Rajesh Vijaya
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,



package projsp;



public class trying

{

private String name;

private int age;

public void setName(String n)

{

name=n;

}

public void setAge(int a)

{

age=a;

}



public int getAge()

{

return age;

}

public String getName()

{

return name;

}

}



The contents of test.jsp file are as follows:



<%@ page language="java" import="projsp.*" %>

<jsp:useBean id="test" class="projsp.trying" />



<html>

The Name is <getProperty name="test" property="name" />

The Age is < jsp:getProperty name="test" property="age" />

</html>



If a user types in http://servername:8080/test.jsp?name=Anand&age=22 the out put is
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Didn't you forget a setProperty anywhere ?
 
Saravanan Viswanathan
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Answer would be
The Name is
The Age is 22

jsp:useBean standard action will create a bean if it doesn't exist in the scope specified.
 
Saravanan Viswanathan
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Answer for 1st line wud be like this, bcoz its not a standard action.
The Name is <getProperty name="test" property="name" />
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic