0

hi,
can u tel me where should i place the code for database connection?..is it placed in the same directory as other jsp and html files?....shall i put it in a java bean and then include it in all the other jsp files?..i

3
Contributors
3
Replies
4
Views
9 Years
Discussion Span
Last Post by Ankita B
0

You can always create an class and place the code there and then use the class in your jsp pages to access the DB.

0

Never ever put business / backend logic in your JSP file. It's not what it was meant for. JSP is a presentation technology. Place your logic inside Servlets / EJB's and use DAO(Data Access Objects) to access your database. Reading the official J2EE tutorial would clear up things for you.

0

thx a lot..i tried doin that..but an error is comin..

first file name is main.jsp. process.jsp is the action file and login.java is the db connection class.i placed login in a folder named foo under classes in WEB-INF (WEB-INF->classes->foo->login.java)...but it still shows the error..
HTTP Status 500 -

--------------------------------------------------------------------------------

type Exception report

message

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: /process.jsp

Generated servlet error:
[javac] Compiling 1 source file

C:\Program Files\Apache Group\Tomcat 4.1\work\Standalone\localhost\ankita\process_jsp.java:43: package foo does not exist
foo.Login idHandler = null;
^

An error occurred at line: 2 in the jsp file: /process.jsp

Generated servlet error:
C:\Program Files\Apache Group\Tomcat 4.1\work\Standalone\localhost\ankita\process_jsp.java:45: package foo does not exist
idHandler = (foo.Login) pageContext.getAttribute("idHandler", PageContext.REQUEST_SCOPE);
^

An error occurred at line: 2 in the jsp file: /process.jsp

Generated servlet error:
C:\Program Files\Apache Group\Tomcat 4.1\work\Standalone\localhost\ankita\process_jsp.java:48: package foo does not exist
idHandler = (foo.Login) java.beans.Beans.instantiate(this.getClass().getClassLoader(), "foo.Login");
^
3 errors

please help..

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.