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

Recommended Answers

All 3 Replies

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

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.

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..

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.