Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Using a JavaBean tags in a JSP page

 
Jaya Sree
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi guys,I am new to JSP technology.I try to insert java bean tags in JSP page.
the code is given below.

public class Book
{
private string title;
public Book()
{}
public string getTitle()
{
return title;
}
public void setTitle(string title)
{
this.title=title;
}
}

I saved this file as Book.java in web-inf/classes.

and my jsp code is given below.
<html>
<body>
<jsp:useBean id="myBook" class="Book" />
<jsp:setProperty name="myBook" property="title" value="Beginning JSP" />
<jsp:getproperty name="myBook" property="value" />
</body>
</html>


I got an error saying that unable to compile class file for JSP.
do i have to configure the web.xml file?
can anybody please help me with an answer?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64631
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is a recording: place your bean in a package other than the default.
 
Craig Jackson
Ranch Hand
Posts: 405
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And also the correct syntax for the <jsp ropery> tag is


<jsp:getProperty name="beanName" property="propName"/>


were there must be getPropName method defined in your bean class.

Your source code has a lowercase "p" and your bean class does not have a getValue method defined in your bean component.




I hope this helps.

Craig.
 
Jaya Sree
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for ur help,it's working right now.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic