• 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
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

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" />
 
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic