Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes 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
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

jsp:useBean Example

 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Didn't you forget a setProperty anywhere ?
 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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" />
 
Curse your sudden but inevitable betrayal! And this tiny ad too!
The trailboss has a kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic