i am new in jsp.i am trying to use useBean in jsp to run a class named hi.
i am using apache tomcat as a web server.i placed the file hi.class as well as the file that i named it date.jsp which uses the hi class in the folder webapps placed folder tocat7.0.
the code is of date.jsp is:

<%@ page import="java.util.*" %>
<%@ page import="java.lang.*" %>
<HTML>
<BODY>
<jsp:useBean id=“my” scope="request" class=“hi”>
<jsp:getProperty name="my" property="*"/>
</jsp:useBean>
<%my.print()%;>
</BODY>
</HTML>

the code of hi.class is:

import java.lang.*;
import java.util.*;
public class hi{
public static int print()
{System.out.println("hi");
return 1;
}
public static void main(String args[])
{System.out.println(print());
}
}

i am getting this error when i run date.jsp in web browser:
org.apache.jasper.JasperException: /date.jsp(5,17) quote symbol expected
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:40)
org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:407)
org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:88)
org.apache.jasper.compiler.Parser.parseAttribute(Parser.java:222)
org.apache.jasper.compiler.Parser.parseAttributes(Parser.java:162)
org.apache.jasper.compiler.Parser.parseAttributes(Parser.java:153)
org.apache.jasper.compiler.Parser.parseUseBean(Parser.java:953)
org.apache.jasper.compiler.Parser.parseStandardAction(Parser.java:1136)
org.apache.jasper.compiler.Parser.parseElements(Parser.java:1449)
org.apache.jasper.compiler.Parser.parse(Parser.java:138)
org.apache.jasper.compiler.ParserController.doParse(ParserController.java:239)
org.apache.jasper.compiler.ParserController.parse(ParserController.java:102)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:197)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:365)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:345)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:332)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:594)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:341)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:389)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:332)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)


note The full stack trace of the root cause is available in the Apache Tomcat/7.0.5 logs.

apreciate any help
thanx

Recommended Answers

All 10 Replies

Seems like you have copy-pasted the code in line 5 in date.jsp.

<jsp:useBean id=“my” scope="request" class=“hi”>

If you look properly you will see that the double quotes for attributes 'id' and 'class' are not normal double quotes.
Try using normal double quotes as shown in the code given below,

<jsp:useBean id="my" scope="request" class="hi">

Hope this helps

You posted the same exact question in a previous thread, which you got an answer. I don't know if it was the right one, but nevertheless, if you had problems you should have posted at the same thread.

And parry_kulk, I believe that you also missed that in his jsp page:

<%my.print()%;>

thanx for ur responses,apreciate

<%@ page import="java.util.*" %>
<%@ page import="java.lang.*" %>
<%@ page import="hi" %>
<HTML>
<BODY>
<jsp:useBean id="my" scope="request" class="hi">
<jsp:getProperty name="my" property="*"/>
</jsp:useBean>
<%my.print()%;>
</BODY>
</HTML>

i've changed my code as u specified but i've got the following error

org.apache.jasper.JasperException: /date.jsp(9,2) Unterminated &lt;% tag
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:40)
org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:407)
org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:132)
org.apache.jasper.compiler.Parser.parseScriptlet(Parser.java:771)
org.apache.jasper.compiler.Parser.parseElements(Parser.java:1437)
org.apache.jasper.compiler.Parser.parse(Parser.java:138)
org.apache.jasper.compiler.ParserController.doParse(ParserController.java:239)
org.apache.jasper.compiler.ParserController.parse(ParserController.java:102)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:197)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:365)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:345)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:332)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:594)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:341)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:389)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:332)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
thanx

thanx for ur responses,apreciate

<%@ page import="java.util.*" %>
<%@ page import="java.lang.*" %>
<%@ page import="hi" %>
<HTML>
<BODY>
<jsp:useBean id="my" scope="request" class="hi">
<jsp:getProperty name="my" property="*"/>
</jsp:useBean>
<%my.print()%;>
</BODY>
</HTML>

i've changed my code as u specified but i've got the following error

org.apache.jasper.JasperException: /date.jsp(9,2) Unterminated &lt;% tag
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:40)
org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:407)
org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:132)
org.apache.jasper.compiler.Parser.parseScriptlet(Parser.java:771)
org.apache.jasper.compiler.Parser.parseElements(Parser.java:1437)
org.apache.jasper.compiler.Parser.parse(Parser.java:138)
org.apache.jasper.compiler.ParserController.doParse(ParserController.java:239)
org.apache.jasper.compiler.ParserController.parse(ParserController.java:102)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:197)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:365)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:345)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:332)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:594)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:341)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:389)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:332)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
thanx

Apparently you ignored the answer that I gave you at your other double post and at this one. Other people cared to give you the answer. Did you bother reading it?

line 9

<%my.print()%;>

change to

<%my.print();%>

thanx
i've tried <%my.print();%> and getting this error
at line5 which is: <jsp:useBean id="my" scope="request" class="khaled.hi">
org.apache.jasper.JasperException: /date.jsp(5,0) The value for the useBean class attribute khaled.hi is invalid.
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:40)
org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:407)
org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:148)
org.apache.jasper.compiler.Generator$GenerateVisitor.visit(Generator.java:1226)
org.apache.jasper.compiler.Node$UseBean.accept(Node.java:1182)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2376)
org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2428)
org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2434)
org.apache.jasper.compiler.Node$Root.accept(Node.java:475)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2376)
org.apache.jasper.compiler.Generator.generate(Generator.java:3475)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:249)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:365)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:345)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:332)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:594)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:341)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:389)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:332)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)

Where's this line?

<jsp:useBean id="my" scope="request" class="khaled.hi">

i think the one in your original post

<jsp:useBean id="my" scope="request" class="hi">

is correct. If you use class="khalid.hi"

that means khalid is a package and hi is the class contained within that package.

if this is not the case, then change it back to class="hi" and see if you still encounter any errors (",)

thanx eric for response,
i've put the Date.jsp where it contains the code i've posted and hi.class java file
where i've used it in useBean in a folder named khaled in webapps in tomcat folder.
i've tried the 2 cases,i.e class="khaled.hi" and class="hi",and i am getting the same error when i run it in my browser as://localhost:8080\khaled\date.jsp.

you need to put the Date.jsp in the webapps folder but the hi.class file should be inside WEB-INF folder and inside classes folder.


for jsp:

webapps/Date.jsp

for classes

webapps/WEB-INF/classes/packageName/hi.class


NOTE: if you put your classes inside a package, you need to import that packeage inside your java class

package khalid;

if you dont have this in your java class then your class is not packaged. In this case, your folder tree should look like this.

webapps/WEB-INF/classes/hi.class

i've put it in webapps/examples/WEB-INF/classes/hi.class.bcs webapps/web-inf/classes does not exist.and still getting the same error.i don't know what is the problem
thanx

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.