Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

The value for the useBean class attribute StringBean is invalid

 
Rupal Rshah
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Friends..

I am using Tomcat 6.0.20 and trying to use beans in JSP..

The JSP file is under a folder JSPWork....and the web.xml is under the WEB-INF folder within JSPWork and the class file for bean is under classes folder of the WEB-INF of JSPWork.

the code in StringBean.jsp is:
<html>
<head>
<title>Using JavaBeans with JSP</title>
</head>

<body>
<table border="5" align="center">
<tr> <th> Using JavaBeans with JSP</th>
</table>

<jsp:useBean id="StringBean" class="StringBean" scope="session"/>


<ol>
<li>Initial Value (from jsp:getProperty):
<i><jsp:getProperty name="StringBean" property="message"/></i> </li>

<li>Initial Value (from jsp expression):
<i><%= StringBean.getMessage() %></i> </li>

<li><jsp:setProperty name="StringBean" property="message" value="I Love Beans"/>
Value after setting property with jsp:setProperty:
<i><jsp:getProperty name="StringBean" property="message"/></i>
</li>

<li><% StringBean.setMessage("I Love Web Techno"); %></i>
Value after setting property with scripplet:
<i><%= StringBean.getMessage() %></i>
</li>
</ol>
</body>
</html>


************THe StringBean.java *************

public class StringBean {
private String message = "Initialized....";

public StringBean() {}
public String getMessage() {
return(message);
}

public void setMessage(String message){
this.message = message;
}
}


******************WEB.xml***********
<servlet>
<servlet-name>StringBean</servlet-name>
<servlet-class>StringBean</servlet-class>
</servlet>


<servlet-mapping>
<servlet-name>StringBean</servlet-name>
<url-pattern>/StringBean</url-pattern>
</servlet-mapping>


Its is giving the error as class is invalid.....

Pease help
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64973
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Rupal Sh", please check your private messages for an important administrative matter. Thanks.

Also, please be sure to use code tags when posting code to the forums. Unformatted or unindented code is extremely hard to read and many people that might be able to help you will just move along to posts that are easier to read. Please click this link ⇒ UseCodeTags ⇐ for more information.

Properly indented and formatted code greatly increases the probability that your question will get quicker, better answers.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64973
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All classes used in web applications must be in a package other than the default.
 
Rupal Rshah
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for the specification...will take care next onwards...

but putting in package does not work...
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64973
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please read ItDoesntWorkIsUseless. Please elaborate.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic