permaculture playing cards*
The moose likes JSP and the fly likes Bean In JSP problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » JSP
Bookmark "Bean In JSP problem" Watch "Bean In JSP problem" New topic
Author

Bean In JSP problem

Upendra Bhole
Greenhorn

Joined: Dec 05, 2004
Posts: 22
Hi to all,

I facing problem while executing JSP .I using bean
eith JSP .HTML code for program is as follows

<HTML>
<BODY>
<FORM METHOD=POST ACTION="SaveName.jsp">
What's your name? <INPUT TYPE=TEXT NAME=username SIZE=20><BR>
What's your e-mail address? <INPUT TYPE=TEXT NAME=email SIZE=20><BR>
What's your age? <INPUT TYPE=TEXT NAME=age SIZE=4>
<P><INPUT TYPE=SUBMIT>
</FORM>
</BODY>
</HTML>

_____________________________________________________________________

JSP code for program is :

<jsp:useBean id="user" class="UserData" scope="session"/>
<jsp:setProperty name="user" property="*"/>
<HTML>
<BODY>
<A HREF="NextPage.jsp">Continue</A>
</BODY>
</HTML>
_____________________________________________________________________

<jsp:useBean id="user" class="UserData" scope="session"/>
<HTML>
<BODY>
You entered<BR>
Name: <%= user.getUsername() %><BR>
Email: <%= user.getEmail() %><BR>
Age: <%= user.getAge() %><BR>
</BODY>
</HTML>


_______________________________________________________________

public class UserData {
String username;
String email;
int age;

public void setUsername( String value )
{
username = value;
}

public void setEmail( String value )
{
email = value;
}

public void setAge( int value )
{
age = value;
}

public String getUsername() { return username; }

public String getEmail() { return email; }

public int getAge() { return age; }
}

I am using jdk1.4 with j2sdkee1.3 on OS XP.
while excuting program in explorer i set the paths as

set path=d:\jdk1.4\bin;d:\j2sdkee1.3\bin
set classpath=.;d:\jdk1.4\lib\;d:\j2sdkee1.3\lib\j2ee.jar;D:\j2sdkee1.3\lib\classes
set JAVA_HOME=d:\jdk1.4
set J2EE_HOME=d:\j2sdkee1.3

I am puting the HTML and jsp file in public_html folder while class files in lib\classes folder .I am getting error as

A Servlet Exception Has Occurred
org.apache.jasper.JasperException: Unable to compile class for JSPd:\j2sdkee1.3\repository\prashant-k9u684\web\_0002fSaveName_jsp.java:57: Class org.apache.jsp.UserData not found.
UserData user = null;
^
d:\j2sdkee1.3\repository\prashant-k9u684\web\_0002fSaveName_jsp.java:60: Class org.apache.jsp.UserData not found.
user= (UserData)
^
d:\j2sdkee1.3\repository\prashant-k9u684\web\_0002fSaveName_jsp.java:65: Class org.apache.jsp.UserData not found.
user = (UserData) java.beans.Beans.instantiate(this.getClass().getClassLoader(), "UserData");
^
3 errors

at org.apache.jasper.compiler.Compiler.compile(Compiler.java:277)
at org.apache.jasper.servlet.JspServlet.loadJSP(JspServlet.java:523)
at org.apache.jasper.servlet.JspServlet$JspServletWrapper.loadIfNecessary(JspServlet.java:175)
at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:187)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:379)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:453)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:254)
at org.apache.catalina.core.ApplicationFilterChain.access$0(ApplicationFilterChain.java:198)
at org.apache.catalina.core.ApplicationFilterChain$1.run(ApplicationFilterChain.java:177)
at java.security.AccessController.doPrivileged(Native Method)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:255)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:882)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:225)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.valves.CertificatesValve.invoke(CertificatesValve.java:246)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:882)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2227)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.authenticator.SingleSignOn.invoke(SingleSignOn.java:229)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:882)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:162)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:882)
at org.apache.catalina.connector.http.HttpProcessor.process(HttpProcessor.java:875)
at org.apache.catalina.connector.http.HttpProcessor.run(HttpProcessor.java:952)
at java.lang.Thread.run(Thread.java:579)


Please help me.

Thanks and Regards ,

Upendra .
Shrinivas Mujumdar
Ranch Hand

Joined: Aug 27, 2004
Posts: 328
Hello Upendra,
Check Your package name...for bean you have written there.in <jsp:useBean> specify fully qualified name of the class you are using also check whether you have copied .class file at correct location under classes folder.

Shrinivas
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42022
    
  64
You should not use classes as beans that are not in a particular package. Move the UserData class into some package, e.g. "x", change all the references to "x.UserData", and it should work, as long as the class is in your WEB-INF/classes hierarchy.


Ping & DNS - my free Android networking tools app
Upendra Bhole
Greenhorn

Joined: Dec 05, 2004
Posts: 22
Dear Ulf Dittmer ,Shrinivas Mujumdar

I am using J2EE Server.Please suggest me where should I put the .class file of bean class.
Also I am not using any package in my the bean class.
Suggest ...
Upendra
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61298
    
  66

Originally posted by Upendra Bhole:
Please suggest me where should I put the .class file of bean class.


The class files must go in the package hierarchy under the WEB-INF/classes folder.


Also I am not using any package in my the bean class.


Start. As of JDK 1.4 non-packaged classes cannot be imported.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
GeeCON Prague 2014
 
subject: Bean In JSP problem