Can any one tell me how to use a Java Object in a JSP file i.e I have written a connection class and want to instantiate an object of this class so that the JSP can connect to the database. Do I have to import it or include it ?? :-|

Recommended Answers

All 2 Replies

The JSP will need to have access to the class of course. That means importing the package the class is in.
After that you can instantiate it like everything else.

BUT (and that's a very big BUT) you should really not do that. You should use a servlet for stuff like that and use the JSP (which you should build using JSTL) only for displaying results.

You should at all times strive to write JSPs without any Java code at all.

You should like he said split things up. If I remember right it's called MVC architecture, and is worth looking into.

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.