• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problem Using Bean in JSP

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have a very simple program which says hello using a bean. Somehow tom cat does not seem to find the been class.
I have my jsp page under:
Tomcat 4.1\webapps\paviBean\jsp\Hello.jsp
and bean class fiile under:
Tomcat 4.1\webapps\paviBean\Web-inf\classes\mypackage\HelloBean.class.
My code for Hello.jsp:
<%-- Hello.jsp --%>
<%@ page import = "mypackage.HelloBean" %>
<jsp:useBean id="hello" class="mypackage.HelloBean" >
<jsp:setProperty name="hello" property="*" />
</jsp:useBean>

<HTML>
<HEAD><TITLE>HEllo</TITLE></HEAD>
<BODY>
<H1>
Hello
</H1>
</BODY>
</HTML>
Code for HelloBean.java:
package mypackage;
public class HelloBean {
private String name = "world";
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
}

I get the following error:
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: Unable to compile class for JSP
An error occurred at line: 2 in the jsp file: /jsp/Hello.jsp
Generated servlet error:
[javac] Compiling 1 source file
C:\Program Files\Apache Group\Tomcat 4.1\work\Standalone\localhost\paviBean\jsp\Hello_jsp.java:7: package mypackage does not exist
import mypackage.HelloBean;
^
C:\Program Files\Apache Group\Tomcat 4.1\work\Standalone\localhost\paviBean\jsp\Hello_jsp.java:44: package mypackage does not exist
mypackage.HelloBean hello = null;
^
An error occurred at line: 2 in the jsp file: /jsp/Hello.jsp
Generated servlet error:
C:\Program Files\Apache Group\Tomcat 4.1\work\Standalone\localhost\paviBean\jsp\Hello_jsp.java:46: package mypackage does not exist
hello = (mypackage.HelloBean) pageContext.getAttribute("hello", PageContext.PAGE_SCOPE);
^
An error occurred at line: 2 in the jsp file: /jsp/Hello.jsp
Generated servlet error:
C:\Program Files\Apache Group\Tomcat 4.1\work\Standalone\localhost\paviBean\jsp\Hello_jsp.java:49: package mypackage does not exist
hello = (mypackage.HelloBean) java.beans.Beans.instantiate(this.getClass().getClassLoader(), "mypackage.HelloBean");
^
4 errors

at org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:130)
at org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:293)
at org.apache.jasper.compiler.Compiler.generateClass(Compiler.java:340)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:352)
at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:474)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:184)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:260)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2415)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:223)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:432)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:386)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:534)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:530)
at java.lang.Thread.run(Thread.java:536)

Can anyone please help?
Thanks
Pavitra
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My code for Hello.jsp:
<%-- Hello.jsp --%>
<%@ page import = "mypackage.HelloBean" %>
<jsp:useBean id="hello" class="mypackage.HelloBean" >
<jsp:setProperty name="hello" property="*" />
</jsp:useBean>
Hi,
I think you have missed the "scope" attribute in the useBean tag. Hope it helps.
Good luck
Deepak
 
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
See if your HelloBean has been compiled (HelloBean.class file present).
 
pavitra nagaraja
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I addes scope="session" and made sure that the class file is created. Still no luck. Does anyone know if any path variable needs to be set?
Thanks
 
boyet silverio
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think I see it. See your 'Web-inf' directory name. It has to be all capital letters i.e. WEB-INF. It is what Tomcat recognizes and not .../Web-inf/.... You have to change this directory name to all caps and refer to it in all caps also e.g. "..../WEB-INF/..."
If, after changing it to all caps in the file/directory-explorer, it reverts back unchanged, the feature may not have been enabled. So you have to enable it under Folder Options.
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by boyet silverio:
It has to be all capital letters i.e. WEB-INF. It is what Tomcat recognizes and not .../Web-inf/.... You have to change this directory name to all caps and refer to it in all caps also e.g. "..../WEB-INF/..."


is this really true? when I installed my Tomcat the folder name was not in all capitals. After I changed it, now the server is totally down.
 
Author
Posts: 170
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Annina WG:

is this really true? when I installed my Tomcat the folder name was not in all capitals. After I changed it, now the server is totally down.


The WEB-INF folder must be in capitals, not the Tomcat folder itself.
Cheers
Sam
 
Annina WG
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I did mean "WEB-inf" folder.
my program ran well before holiday. Today after I read this post, I changed my folder name too.And then I find my program doesn't work,even the examples of Tomcat.Now I am going to reinstall Tomcat!!
 
boyet silverio
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
wow! i almost missed out on the bloody red-hot-fuming graemlin and its kinda cute.
Annina. what i pointed out to pavitra was something which occurred to me back then and caused me some trouble. it was remedied when the web-inf dir name was changed to all caps.
i think you better check also other angles on why your tomcat server went down. else, that server may go down again (or that others on the receiving end may find the fuming graemlin not cute enough). Hopefully that's not a production server you're testing with... after the holidays.
Or better, if you want, post more detailed circumstances which participants here could help you coolly examine. cheers!
 
pavitra nagaraja
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I put all my jsps and classes in tomcat's example directory.(Because their bean examples worked!!). Guess what, my beans started working too. I guess there is some configuration I'm missing.
Thanks for all your help. Will post a reply if I figureout what it is.
Thanks
Pavitra
 
Annina WG
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
boyet,I believe what you said is your true experience.
Now I have reinstalled Tomcat and it works well again. I cannot figure out what happened. But the directory name is still not in all caps, not only "Web-inf" but also "Root" directory.
is this the reason why Beans donn't work? I meet trouble with Beans also.
I downloaded "jakarta-tomcat-4.1.15-LE-jdk14" version of Tomcat and followed instructions on moreservlets website. it works as standalone server on my windows NT desktop.
 
boyet silverio
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
<quote>
is this the reason why Beans donn't work? I meet trouble with Beans also.
</quote>
Annina and Pavitra,
To produce the same errors Pavitra mentioned, I found time to run his code (on tomcat 4.0. and 4.1). I changed my WEB-INF to small caps (actually did several caps variations, just in case). I did produce the errors exactly. When I put back my WEB-INF to all caps then restarted Tomcat, his code run fine.
Also did several tests on his jsp. I removed his <useBean> references, changed my WEB-INF to lower caps and yep, it run fine. Put the <useBean> back again and corrected WEB-INF, and there its fine again. Without any jsp tags (for Pavitra's code), Tomcat seem to consider a .jsp file just another .html file and (for this) isn't really strict about the caps format. But if there is a jsp tag or a reference of transferring control to a servlet (which I added to the code, and lowered web-inf's caps), then Tomcat presents errors either immediately upon access to the page or during the moment of transferring control to another servlet. I think this is somewhat related to your case Annina.
You mentioned Annina that when you re-installed, tomcat your root and web-inf were not still in all caps, look for 'allow all uppercase names' or similar...I think this is in folder options... and enable it before reinstalling (take precautions though ).
Also, restart tomcat whenever you tweak WEB-INF and its elements (althogh later, you could explore some configs to avoid some restarts).
Anyway, you're almost there, if not already there... cheers
 
Annina WG
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by boyet silverio:

You mentioned Annina that when you re-installed, tomcat your root and web-inf were not still in all caps, look for 'allow all uppercase names' or similar...I think this is in folder options... and enable it before reinstalling (take precautions though ).


yes, I think this is the better way.if I change the letters after installation, it won't work well. Unfortunately I have no administrator right of my PC,have to wait for the system administrator untill monday. Hope this will solve my problem.
Thanks again to boyet! have a nice weekend!
 
Annina WG
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
good news! I get my result
thanks boyet!
 
boyet silverio
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
welcome. glad to be of help.
 
reply
    Bookmark Topic Watch Topic
  • New Topic