aspose file tools*
The moose likes JSP and the fly likes Error running JSP file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Error running JSP file" Watch "Error running JSP file" New topic
Author

Error running JSP file

Roshini Sridharan
Ranch Hand

Joined: Jan 16, 2001
Posts: 143
I am trying to develop a simple JSP page that calls Java code for manipulation. The following is the JSP file, the web.xml and the Error log.

Kindly help me identifying the problem created since i am new using the Java code with JSP separately.

MyJsp.jsp


Web.xml

Error

org.apache.jasper.JasperException: /MyJsp.jsp(13,0) The value for the useBean class attribute Calculator is invalid.
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:39)
org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:405)
org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:146)
org.apache.jasper.compiler.Generator$GenerateVisitor.visit(Generator.java:1223)
org.apache.jasper.compiler.Node$UseBean.accept(Node.java:1116)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2163)
org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2213)
org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2219)
org.apache.jasper.compiler.Node$Root.accept(Node.java:456)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2163)
org.apache.jasper.compiler.Generator.generate(Generator.java:3268)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:189)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:286)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:267)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:255)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:556)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:296)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:245)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
note The full stack trace of the root cause is available in the Apache Tomcat/5.5.7 logs.

Thanx in advance
Regards
Roshini.S
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Your beans need to be packaged. This is a Java issue that has to due with a tightning of the JVM implementation in 1.4.1 and up.

Also, your calculator class will need a zero argument constructor (if it doesn't already have one) to be instanciated from a useBean tag.
[ May 27, 2005: Message edited by: Ben Souther ]

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Roshini Sridharan
Ranch Hand

Joined: Jan 16, 2001
Posts: 143
Thank you Ben for your instant reply. I will pack the Bean file, i have provided the zero argument constructor already.

Regards
Roshini
Roshini Sridharan
Ranch Hand

Joined: Jan 16, 2001
Posts: 143
I still get the same error even after packing the code,

does the following error have something to do with this, as i am new to configuring web app in tomcat5.5.7.

INFO: Missing application web.xml, using defaults only StandardEngine[Catalina].
StandardHost[localhost].StandardContext[/roshini]

Kindly suggest How do i correct the above problem.

Regards
Roshini
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Can you post the directory structure of your webapp?
If Tomcat can't find your web.xml file, my guess is that things may
not be laid out properly.
Roshini Sridharan
Ranch Hand

Joined: Jan 16, 2001
Posts: 143
Hi,

The directory structure is as follows


Thanx for your replies.

Regards
Roshini.S
[ May 30, 2005: Message edited by: roshini sridhar ]
Jeffrey Spaulding
Ranch Hand

Joined: Jan 15, 2004
Posts: 149
Everything in tomcat land is case sensitive.

If you name your WEB-INF WEB-INF instad of web-inf the app should come up.

J.
Roshini Sridharan
Ranch Hand

Joined: Jan 16, 2001
Posts: 143
[WEB-INF] folder is in upper case only.
sergio mendez-rueda
Ranch Hand

Joined: May 12, 2005
Posts: 37
hi roshini,

there are a lot of postings (in java ranch)
like this one.
this a posible solution of your problem:


your web-app is roshini (case sensitiv)

file and directory of your web-deployment(tomcat or resin)

C:\Progamme\Tomcat5.0\wabapps\roshini (root directory of your web-app)
| form.html
| MyJsp.jsp
\---WEB-INF
| web.xml (your application don't need a dd (wex.xml)(why??)
|
\---classes
\---com
\---example
\---model
Calculator.class
<!-- End of the deployement -->

<!-- Source Code -->

Begin------------------form.html-------------Begin

<html>
<body>
<form action="MyJsp.jsp">
first operand:<input type="text" name="x"><br>
second operand:<input type="text" name="y"><br>
operand (+, -, oder *):<input type="text" name="c"><br>
<input type="submit">
</form>
</body>
</html>
End------------------form.html-----------------End

Begin----------------MyJsp.jsp---------------Begin
<Html>
<Head>
<Title>Roshini's JSP</Title>
</Head>
<Body>
<%
int X= 0;
int Y= 0;
char O= '+';
X = Integer.parseInt(request.getParameter("x").trim());
Y = Integer.parseInt(request.getParameter("y").trim());
O = request.getParameter("c").trim().charAt(0);
%>

<jsp:useBean id="cal" class="com.example.model.Calculator" scope="page"/>

<%
cal.setX(X);
cal.setY(Y);
cal.setC(O);
%>
Your result is:
<jsp:getProperty name="cal" property="x"/>
<jsp:getProperty name="cal" property="c"/>
<jsp:getProperty name="cal" property="y"/>
=
<%= cal.getResult() %>
<hr>
<% out.println("HI, MY CALCULATOR WORKS"); %>
<hr>
</Body>
</Html>
End------------------MyJsp.jsp------------------End

Begin----------------Calculator.java-----------Begin

package com.example.model;

public class Calculator {

private int x = 0;
private int y = 0;
private char c = '+';

public Calculator() {}

public Calculator(int x, int y, char c) {
setX(x);
setY(y);
setC(c);
}

public void setX(int x) {
this.x = x;
}

public void setY(int y) {
this.y = y;
}

public void setC(char c) {
this.c = c;
}

public int getX() {
return x;
}

public int getY() {
return y;
}

public char getC() {
return c;
}

public int getResult() {
if (c == '+')
return (x + y);
if (c == '-')
return (x - y);
if (c == '*')
return (x * y);
return 1;
}

}
End------------------Calculator.java-------------End

<!-- End source code -->
that's all folk's

(sorry, but this is a "beginners approach", scriplets? oh my good! ...)
cheers,
ser
Roshini Sridharan
Ranch Hand

Joined: Jan 16, 2001
Posts: 143
Hi,

Thanx a lot, the eg provided is working...

Regards
Roshini
kirtikumar patel
Greenhorn

Joined: Jun 29, 2005
Posts: 14
hi! rosani
have you got where is your mistake in your example ?
see your classpath in class attribute in usebean tag,
[ June 29, 2005: Message edited by: Bear Bibeault ]

kirti patel<br />software engiener<br />pune
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

kirtikumar,

First, welcome to Javaranch and thank you for participating.

One tip:
If a thread hasn't been touched for more than a week or so it's considered dead. Very often the original poster has solved their problem or has moved on. Bringing them to the top of the list pushes the more recent ones down and may cause them to be missed.

The term for such a resurrected thread is 'zombie' (walking dead).
Bringing up zombies is not encouraged.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Error running JSP file