JSP functions/methods page question

J

johnston_58

Hi,

I am learning JSP. I have previously done ASP and PHP.

My question is, is it possible to create a function/method jsp page.
What I mean is, if i wanted to open a DB connection could I have a
seperate JSP page that contained a function to open the connection so i
could include this page whenever I need to connect to a db.
Is this possible?

Thanks
J
 
H

Heiner Kücker

Hi,

I am learning JSP. I have previously done ASP and PHP.

My question is, is it possible to create a function/method jsp page.
What I mean is, if i wanted to open a DB connection could I have a
seperate JSP page that contained a function to open the connection so i
could include this page whenever I need to connect to a db.
Is this possible?

Thanks
J

You can define an method in a jsp page with

<%!
private java.sql.Connection getConnection()
{
....
and so on
}
%>


The <%! sequence meant, the code is included in the class le­vel in the jsp class:

puclic class jsp_xxxx {


-- your code ---


Must be code for sitting in the class declaration,
an variable or const declaration or an method.


The <% sequence meant, the code is included in the class lev­el in the jsp class:


puclic class jsp_xxxx {


public void jspService() {


-- your code ---


Must be code for running in the jspService method.





Heiner Kuecker
Internet: http://www.heinerkuecker.de http://www.heiner-kuecker.de
JSP WorkFlow PageFlow Page Flow FlowControl Navigation: http://www.control-and-command.de
Java Expression Formula Parser: http://www.heinerkuecker.de/Expression.html
CnC Template Technology http://www.heinerkuecker.de/Expression.html#templ
Domain Specific Languages http://www.heinerkuecker.de/DomainParser.html
 
N

Nick

Hi,

I am learning JSP. I have previously done ASP and PHP.

My question is, is it possible to create a function/method jsp page.
What I mean is, if i wanted to open a DB connection could I have a
seperate JSP page that contained a function to open the connection so i
could include this page whenever I need to connect to a db.
Is this possible?

Thanks
J

What you could do is use Servlets and using the the
Model-View-Controller (MVC)architecture you can have all of your methods
in the servlet and call them from different servlets--then send a call
to the JSP.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,053
Latest member
BrodieSola

Latest Threads

Top