Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

problem with jsp:useBean tag  RSS feed

 
ayodele lilkay
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am new to jsp programming. I have this code trying to access a variable from a javabean class:

<jsp:useBean id="login" class="com.mybean.login.LoginBean" >
<jsp:setProperty name="login" property="userName" value="myName" />
Welcome <jsp:getProperty name="login" property="userName" />

but seem to get this error when i run it on tomcat:

The class value for <jsp:useBean/> "com.mybean.login.LoginBean" is invalid.

i dont know if i have to configure anything else in the web.xml file. Pls sum1 help
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you post the code for LoginBean?
 
ayodele lilkay
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ben Souther:
Can you post the code for LoginBean?


package com.mybean.login;

public class LoginBean {
String userName;
String password;

LoginBean() {
userName = null;
password = null;
}

public void getUserName() {
return this.userName;
}

public String setUserName( String userName ) {
this.userName = userName;
}

public void getPassword() {
return this.password;
}

public String setPassword( String password ) {
this.password = password;
}
}

this is the LoginBean code. would appreciate an urgent response
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First, a couple things that will make it easier for people on this site to help you.

In this code, your useBean tag is not closed.

I'm guessing (from the error message) that is is in your real code.
Please make sure you cut and paste the real code when posting your question.
This will save us from wasting a lot of time chasing down non-issues.
See: http://faq.javaranch.com/view?AvoidRedHerrings
and: http://faq.javaranch.com/view?PostRealCode
for more information.


Also, if you wrap your code in a set of UBB code tags, your indenting will be preserved. This makes it easier for others to read your code which makes it easier (and thus more likely that they will..) help you.
See: http://faq.javaranch.com/view?UseCodeTags

At a quick glance, the bean looks OK, Where did you put the class file?
 
ayodele lilkay
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ben Souther:
First, a couple things that will make it easier for people on this site to help you.

In this code, your useBean tag is not closed.

I'm guessing (from the error message) that is is in your real code.
Please make sure you cut and paste the real code when posting your question.
This will save us from wasting a lot of time chasing down non-issues.
See: http://faq.javaranch.com/view?AvoidRedHerrings
and: http://faq.javaranch.com/view?PostRealCode
for more information.


Also, if you wrap your code in a set of UBB code tags, your indenting will be preserved. This makes it easier for others to read your code which makes it easier (and thus more likely that they will..) help you.
See: http://faq.javaranch.com/view?UseCodeTags

At a quick glance, the bean looks OK, Where did you put the class file?


ok thanks for the tip. I pasted my class file in WEB-INF/classes/com/mybean/login
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmm...

Any other information in the log files?
There should be verbose stack trace in one of them.
 
ayodele lilkay
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ben Souther:
Hmm...

Any other information in the log files?
There should be verbose stack trace in one of them.


Thanks a lot for taking time to respond to my problem, but i jst found out the problem: the class constructor wasnt pblic while the class itself is.
Thanks again.
 
vivek dhanker
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ayodele lilkay,

Use this code hope it will work

<jsp:useBean id="login" class="com.mybean.login.LoginBean" />
<jsp:setProperty name="login" property="UserName" value="myName" />
Welcome <jsp:getProperty name="login" property="UserName" />


==============



package com.mybean.login;

public class LoginBean implements java.io.Serializable {
String userName;
String password;

LoginBean() {
userName = null;
password = null;
}

public void setUserName( String userName ) {
this.userName = userName;
}

public String getUserName() {
return username;
}

public void setPassword( String password ) {
this.password = password;
}

public String getPassword() {
return this.password;
}
}
 
Shivani Chandna
Ranch Hand
Posts: 380
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Ayodele,
Your constructor is not public - .

One needs to have a public no arg constructor to use the class in jsp:useBean

Regards,
Shivani
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you read his last post, I think he already knows this
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!