why can't my jsp use this bean?

hi,

i'm stuck with this problem since yesterday. hope anyone can help me sort this out. i'll try to state my problem here as clear as possible...

i have a jsp page named call.jsp which i put in the folder

C:\Tomcat 5.5\webapps\ROOT\mypage\

here's the content (partially) of the call.jsp

<%@ pageimport ="login.*" %>

<jsp:useBean id="mybean" class="login.loginDB"/>

and here's the content of the bean which this call.jsp is trying to call. name of the bean is loginDB.java. i put the the loginDB.java inside this folder:

C:\Tomcat 5.5\webapps\ROOT\mypage\WEB-INF\classes\login

then i compiled the java file using the command prompt

C:\Tomcat 5.5\webapps\ROOT\mypage\WEB-INF\classes\login\javac loginDB.java

and so the output is loginDB.class which obviously is placed in the folder C:\Tomcat 5.5\webapps\ROOT\mypage\WEB-INF\classes\login\

here's the content of loginDB.java:

package login;

import java.sql.*;

import java.util.*;

publicclass loginDBimplements java.io.Serializable{

private String dbServer ="localhost";

private String dbName ="toyo-SMP";

//getter

public String getdbServer(){

return dbServer;

}

public String getdbName(){

return dbName;

}

}

so the problem is, everytime i call call.jsp, this error will come out:

org.apache.jasper.JasperException: /SMP-toyo/logoutPekerja.jsp(85,0) The valuefor the useBeanclass attribute login.loginDB is invalid.

org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:512)

org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)

org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)

org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)

javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

i don't know what else should i to. thanks a lot for helping.

btw i'm using tomcat 5.5.20 with jdk 1.5

[2890 byte] By [imin83a] at [2007-11-26 20:10:57]
# 1
you must also have mutators.. setter methods
jgalacambraa at 2007-7-9 23:14:55 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

I got it why you are getting below above error: You should have a public constructor in your bean class without any arguments. Modify your bean like this:

package login;

import java.sql.*;

import java.util.*;

public class loginDB implements java.io.Serializable {

private String dbServer = "localhost";

private String dbName = "toyo-SMP";

//Constructor

public loginDB (){

}

//getter

public String getdbServer(){

return dbServer;

}

public String getdbName(){

return dbName;

}

}

sudheer_d123a at 2007-7-9 23:14:55 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

thanks a lot for helping , jgalacambra and sudheer_d123.

anyway it still doesn't work. i've tried putting the setter and create a public constructor, but the same problem still persist.

i'm really sorry, forgot to tell u one important thing, that is, the exact original code i posted earlier works very well if i put them in to jsp-examples folder, which is Tomcat 5.5\webapps\jsp-examples\ for the call.jsp file and Tomcat 5.5\webapps\jsp-examples\WEB-INF\classes\login for the loginDB.java & loginDB.class file.

i think this must be a deployment problem..is it?

imin83a at 2007-7-9 23:14:55 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4
anyone..? i'm still stuck with this problem...
imin83a at 2007-7-9 23:14:55 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5
umm wierd.. try to use type instead of class on your useBean
jgalacambraa at 2007-7-9 23:14:55 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6
hmm thanks a lot i'll try that later and tell u the result.. currently i'm heavily occupied by another project. i'll give u 1 duke dollar first...
imin83a at 2007-7-9 23:14:56 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 7
the credits will be worth if the problem is solved.. ok just reply to this thread on the behavior
jgalacambraa at 2007-7-9 23:14:56 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 8

The jsp:useBean tag is fine, but your classes is in the wrong place.

You can place it in \webapps\ROOT\WEB-INF\classes\, but I'm guessing you're trying to create a context called 'mypage', so the best would be to move it to \webapps\mypage\WEB-INF\classes\ and the jsp's to \webapps\mypage\.

serlanka at 2007-7-9 23:14:56 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...