*
The moose likes JSP and the fly likes please help with tomcat, javabean and jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "please help with tomcat, javabean and jsp" Watch "please help with tomcat, javabean and jsp" New topic
Author

please help with tomcat, javabean and jsp

Ryan G Johnson
Ranch Hand

Joined: Nov 11, 2004
Posts: 33
I did a search of the web and i still cannot solve this problem.

I am using tomcat 4.1.30

I have a jsp that calls a javabean like this:

<jsp:useBean id="myAddressBook" class="myPackage.AddressBook" />

I have my file structure this way:

webapps\myJSPApp\WEB-INF\classes\myPackage

1. I have my .jsp in the myJSPApp directory

2. my addressbook.java and.class in the WEB-INF\classes\myPackage directory.

3. I have a package declared at the top of my bean. My bean is public. All functions are public.

4. I have the path to servlet.jar in my classpath. I have been able to successfully compile other servlets.

5. I have the path to 'myPackage' in my classpath.
Here is the error:


java.lang.IllegalAccessException: Class java.beans.Beans can not access a member of class myPackageAddressBook with modifiers ""

for a further test i tried compiling the servlet.



C:\Tomcat_new\work\Standalone\localhost\myJSPApp\hw6_jsp.java:6: package org.apache.jasper.runtime does not exist
import org.apache.jasper.runtime.*;
^
C:\Tomcat_new\work\Standalone\localhost\myJSPApp\hw6_jsp.java:18: cannot resolve symbol
symbol : class HttpJspBase
location: class org.apache.jsp.hw6_jsp
public class hw6_jsp extends HttpJspBase {
^
C:\Tomcat_new\work\Standalone\localhost\myJSPApp\hw6_jsp.java:61: cannot resolve symbol
symbol : class AddressBook
location: class org.apache.jsp.hw6_jsp
AddressBook myAddressBook = null;
^
C:\Tomcat_new\work\Standalone\localhost\myJSPApp\hw6_jsp.java:63: cannot resolve symbol
symbol : class AddressBook
location: class org.apache.jsp.hw6_jsp
myAddressBook = (AddressBook) pageContext.getAttribute("myAddressBook", PageContext.PAGE_SCOPE);
^
C:\Tomcat_new\work\Standalone\localhost\myJSPApp\hw6_jsp.java:66: cannot resolve symbol
symbol : class AddressBook
location: class org.apache.jsp.hw6_jsp
myAddressBook = (AddressBook) java.beans.Beans.instantiate(this.getClass().getClassLoader(), "myPackage.AddressBook");
^
C:\Tomcat_new\work\Standalone\localhost\myJSPApp\hw6_jsp.java:66: cannot resolve symbol
symbol : method getClass ()
location: class org.apache.jsp.hw6_jsp
myAddressBook = (AddressBook) java.beans.Beans.instantiate(this.getClass().getClassLoader(), "myPackage.AddressBook");
^
6 errors

Tool completed with exit code 1
Ryan G Johnson
Ranch Hand

Joined: Nov 11, 2004
Posts: 33
i tried it again without putting my javabean in a package and i get the following error. classpaths are set properly.

org.apache.jasper.JasperException: Unable to compile class for JSP

An error occurred at line: 12 in the jsp file: /hw6.jsp

Generated servlet error:
[javac] Compiling 1 source file

C:\Tomcat_new\work\Standalone\localhost\myJSPApp\hw6_jsp.java:61: cannot resolve symbol
symbol : class AddressBook
location: class org.apache.jsp.hw6_jsp
AddressBook myAddressBook = null;
^



An error occurred at line: 12 in the jsp file: /hw6.jsp

Generated servlet error:
C:\Tomcat_new\work\Standalone\localhost\myJSPApp\hw6_jsp.java:63: cannot resolve symbol
symbol : class AddressBook
location: class org.apache.jsp.hw6_jsp
myAddressBook = (AddressBook) pageContext.getAttribute("myAddressBook", PageContext.PAGE_SCOPE);
^



An error occurred at line: 12 in the jsp file: /hw6.jsp

Generated servlet error:
C:\Tomcat_new\work\Standalone\localhost\myJSPApp\hw6_jsp.java:66: cannot resolve symbol
symbol : class AddressBook
location: class org.apache.jsp.hw6_jsp
myAddressBook = (AddressBook) java.beans.Beans.instantiate(this.getClass().getClassLoader(), "AddressBook");
^
3 errors


at org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:85)
at org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:248)
at org.apache.jasper.compiler.Compiler.generateClass(Compiler.java:315)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:328)
at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:427)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:142)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:240)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:187)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:809)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:200)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:146)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:209)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:144)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2358)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:133)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:118)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:594)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:116)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:594)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:127)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948)
at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:152)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
at java.lang.Thread.run(Thread.java:534)
Ryan G Johnson
Ranch Hand

Joined: Nov 11, 2004
Posts: 33
one problem i had is that i didn't have an empty constructor. I had a constructor that didn't pass any values, but it had stuff in its function. I took it out. now i get the following errors:

C:\Tomcat_new\work\Standalone\localhost\myJSPApp\hw6_jsp.java:6: package org.apache.jasper.runtime does not exist
import org.apache.jasper.runtime.*;
^
C:\Tomcat_new\work\Standalone\localhost\myJSPApp\hw6_jsp.java:18: cannot resolve symbol
symbol : class HttpJspBase
location: class org.apache.jsp.hw6_jsp
public class hw6_jsp extends HttpJspBase {
^
C:\Tomcat_new\work\Standalone\localhost\myJSPApp\hw6_jsp.java:66: cannot resolve symbol
symbol : method getClass ()
location: class org.apache.jsp.hw6_jsp
myAddressBook = (myPackage.AddressBook) java.beans.Beans.instantiate(this.getClass().getClassLoader(), "myPackage.AddressBook");
^
3 errors

Tool completed with exit code 1
Ryan G Johnson
Ranch Hand

Joined: Nov 11, 2004
Posts: 33
sorry for all the posts. this is my classpath. I'm on windows xp.

c:\jdk\bin; c:\tomcat_new\common\lib\servlet.jar; c:\Tomcat_new\webapps\examples\WEB-INF\classes; c:\Tomcat_new\webapps\myJSPApp; c:\Tomcat_new\webapps\myJSPApp\WEB-INF\classes; c:\Tomcat_new\webapps\myJSPApp\WEB-INF\classes; c:\Tomcat_new\webapps\myJSPApp\WEB-INF\classes\myPackage

(N.Pruett - added spaces to classpath to stop page widening.)
[ November 12, 2004: Message edited by: Nathan Pruett ]
Ryan G Johnson
Ranch Hand

Joined: Nov 11, 2004
Posts: 33
might as well post my bean class....


package myPackage;

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
import java.text.*;


public class AddressBook {

String FName,MName,LName,Sex,Street1,Street2,City,State,Zip,PhoneLocalCode,
PhoneAreaCode,PhoneLastCode,Email,OtherInfo,xmlfield;
String outputFile1 = "c:\\addressbooklog.txt";

String FormArray[] = {"FName","MName","LName","Sex","Street1","Street2","City",
"State","Zip","PhoneLocalCode","PhoneAreaCode","PhoneLastCode",
"Email","OtherInfo"};
HashMap hmKey = new HashMap();
HashMap hmValue = new HashMap();
PrintWriter outfile;


/*AddressBook() {
for (int i = 0; i < FormArray.length; i++)
hmKey.put(FormArray[i],"");
}
*/

public AddressBook(String row) {
String keyVal;

try {
outfile = new PrintWriter(new FileWriter(outputFile1),true);
int i = 0;
//outfile.println("ROWS: "+row);
//outfile.flush();
StringTokenizer in_str = new StringTokenizer(row, "|"); //,true);
//require i< 15 so in order to avoid arrayoutofbounds. If increase elements,
//increase the limit.
outfile.println("test "+row);
while (in_str.hasMoreTokens() && (i < 14)) {
//utfile.println("LOOPS: "+ i);
//outfile.flush();
keyVal = in_str.nextToken();
outfile.println(i+": "+ keyVal+" "+FormArray[i]); //+" "+keyVal);
outfile.println(" "+keyVal);
//outfile.println();
outfile.flush();
if (keyVal.equals("NULL"))
hmKey.put(FormArray[i],"");
else
hmKey.put(FormArray[i],keyVal);
i++;
// keyVal = in_str.nextToken();
/* if (keyVal.equals(null))
keyVal = "";

hmKey.put(FormArray[i],keyVal);

*/ }


}catch (IOException ioException) {

outfile.println("ERROR: "+ioException);
outfile.flush();
}
}

public AddressBook (java.util.HashMap hmKey) {
hmKey = this.hmKey;
}

public AddressBook (HttpServletRequest request)
throws IOException, ServletException {
Enumeration paraNames = request.getParameterNames();

String para = "";
String outPara = "";

for (int i = 0; i < FormArray.length; i++)
hmKey.put("NULL",FormArray[i]);

while (paraNames.hasMoreElements())
{
para = (String)paraNames.nextElement();
String[] values = request.getParameterValues (para);
//if (!para.equalsIgnoreCase("submit"))
// {
//mapped based on key. used to order data
// if (!(request.getParameterValues(para)[0].equals("")))
hmKey.put(para,request.getParameterValues(para)[0]);
// else
// hmKey.put(para,"NULL");
//not currently used. May need in future.
hmValue.put(request.getParameterValues(para)[0],para);
// }
}

for (int i = 0; i<FormArray.length; i++){
outPara = outPara + hmKey.get(FormArray[i])+ "|";
}
}

public AddressBook (String FName, String MName, String LName,String Sex,String Street1,
String Street2,String City,String State,String Zip,String PhoneLocalCode,
String PhoneAreaCode,String PhoneLastCode,String Email,String OtherInfo)
{


FName = this.FName;
MName = this.MName;
LName = this.LName;
Sex = this.Sex;
Street1 = this.Street1;
Street2 = this.Street2;
City = this.City;
State = this.State;
Zip = this.Zip;
PhoneLocalCode = this.PhoneLocalCode;
PhoneAreaCode = this.PhoneAreaCode;
PhoneLastCode = this.PhoneLastCode;
Email = this.Email;
OtherInfo = this.OtherInfo;

}

/* public AddressBook removeNull(AddressBook ab) {
String val = "";
for(int i=0; i<FormArray.length(); i++) {
val = (String)hmKey.get(FormArray[i]);
if (val.equals("NULL"))
hmKey.put
}
*/
public Object getVal(Object keyVal) {
return hmKey.get(keyVal);
}

public String getLName() {
return (String)hmKey.get("LName");
}

public String getFName() {
return (String)hmKey.get("FName");
}


public String getOutRecord()
{
String outrecord = "";
for (int i=0; i<FormArray.length;i++){
if (hmKey.get(FormArray[i]).equals(""))
outrecord = outrecord + "NULL" + "|";
else
outrecord = outrecord + hmKey.get(FormArray[i]) + "|"; }
return outrecord;
}

}
Sean Stephens
Ranch Hand

Joined: Oct 25, 2004
Posts: 40
Judging that jasper runtime is missing... I'd say you're missing your jasper-runtime.jar in your classpath. Its a j2ee jar and should be in the j2eesdk that you are using.

Hope that helps,
Sean
Ryan G Johnson
Ranch Hand

Joined: Nov 11, 2004
Posts: 33
i only have j2se installed. there is nothing in my books about need j2ee installed to run jsps?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60783
    
  65

You don't need the full j2ee installed to run JSP and servlets but you do need a servlet container such as Tomcat.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
ajay halmandge
Greenhorn

Joined: Oct 04, 2005
Posts: 7
Ajay Here!!

Offcourse you get the above three errors ....but can be rectified by following steps...

1----->Set up proper classpath up to /jboss/.../WEB-INF/classes/
2----->There should be package (Single file can not be used...i mean it may be depend on version but in case it worked so)

<jsp:useBean id="objWash" class="test.mysql_bean" scope="page" />

Here test is the package ( i mean a directory in /WEB-INF)classes ,that contains the package classes(here mysql_bean.class) )

Thats it!!!
Good Luck!!!
 
 
subject: please help with tomcat, javabean and jsp
 
Similar Threads
ARRRGGGGHHH - Stupid Javabeans - Again! :(
JSP page error (Unable to compile class for JSP ) HTTP Status 500 -
need help running jsps with tomcat 4.1
Tomcat error HTTP Status 500 -(JSP page error (Unable to compile class for JSP )
Jsp bean error