| Author |
Help in using bean inside JSP
|
Agnit Chatterjee
Greenhorn
Joined: Mar 04, 2011
Posts: 24
|
|
java file: try1.java
1st JSP file
2nd JSP file
I keep on getting some error or the other..........could you please help me.......where am I mistaking! Please help
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56221
|
|
Step 1: Move the Java code out of the JSP and into a Java class. Do it now. Java code in a JSP has been discredited for almost 10 years now and its use is irresponsible.
Step 2: Once you've done that, if you still get errors, please be sure to post the nature of the errors.
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
Agnit Chatterjee
Greenhorn
Joined: Mar 04, 2011
Posts: 24
|
|
|
But I have kept here 2 JSP files and a Java file separately
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56221
|
|
Please read this article for information on properly structuring web applications.
Java has no place inside a JSP. That is an extremely poor practice that went out of favor in 2002.
|
 |
Agnit Chatterjee
Greenhorn
Joined: Mar 04, 2011
Posts: 24
|
|
|
Please help me out.......I can't figure out where the problem is............please help
|
 |
Jeanne Boyarsky
internet detective
Marshal
Joined: May 26, 2003
Posts: 26201
|
|
|
I've added code tags to make your post readable. I can't find where you say what the error is. Can you call attention to that so people can help you?
|
[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
|
 |
Agnit Chatterjee
Greenhorn
Joined: Mar 04, 2011
Posts: 24
|
|
Here is the details of the error I am getting:
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: /myfirst.jsp(4,0) The value for the useBean class attribute jdbc.try1 is invalid.
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:41)
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:1221)
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:3458)
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:342)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:391)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
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.8 logs.
|
 |
Agnit Chatterjee
Greenhorn
Joined: Mar 04, 2011
Posts: 24
|
|
They are giving the error:
Name was not previously introduced as per JSP.5.3
Where is the problem???
|
 |
Jeanne Boyarsky
internet detective
Marshal
Joined: May 26, 2003
Posts: 26201
|
|
Moving back to the JSP forum as this is a JDBC question.
Reposting the relevant lines to make it easier to read.
<%@ page import="jdbc.try1" %>
<jsp:useBean id="try1" scope="application" class="jdbc.try1" />
Where is the class file for try1 located? Is it already defined in the application scope?
Note that it is common convention for classnames to begin with an uppercase letter.
|
 |
Agnit Chatterjee
Greenhorn
Joined: Mar 04, 2011
Posts: 24
|
|
class file for try1 is located inside WEB-INF\classes\jdbc
I had made some modifications........like some silly programming errors in the jdbc portion which I did eradicate........still get the error:
The value for the useBean class attribute jdbc.try1 is invalid.
The new files are as follows:
myfirst.jsp
try1.java
properties.jsp
I had intentionally put the try1.java file in a new package called testing. The other two files are jsp files
|
 |
Vijitha Kumara
Bartender
Joined: Mar 24, 2008
Posts: 3670
|
|
|
Make your class's constructor public, otherwise the container is not be able to instantiate it....
|
SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
|
 |
Agnit Chatterjee
Greenhorn
Joined: Mar 04, 2011
Posts: 24
|
|
|
Thanks to everybody out there who helped me out.............It's finally done!!! My first JSP program using JDBC.feels great.
|
 |
 |
|
|
subject: Help in using bean inside JSP
|
|
|