Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > JSP functions/methods page question

Reply
Thread Tools

JSP functions/methods page question

 
 
johnston_58@hotmail.com
Guest
Posts: n/a
 
      01-28-2005
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

 
Reply With Quote
 
 
 
 
Last Timer
Guest
Posts: n/a
 
      01-28-2005
Search for "jsp include" in your favorite engine and you will find
links like this

http://java.sun.com/products/jsp/syn...axref1112.html

You define functions in a jsp page (local to the page only) by using <%
int myfunction(int a) { return 10*a; %>

 
Reply With Quote
 
 
 
 
Heiner Kücker
Guest
Posts: n/a
 
      01-29-2005
<(E-Mail Removed)> wrote
> 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


 
Reply With Quote
 
Nick
Guest
Posts: n/a
 
      01-29-2005
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> 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.
 
Reply With Quote
 
gary.dunne@gmail.com
Guest
Posts: n/a
 
      01-29-2005
Hi,

Thanks to all who replied.
I am using :
> <%!
> private java.sql.Connection getConnection()
> {

and this is working great.

Thanks again,
J

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
JSP newbie - <jsp:useBean > question zalek Java 1 08-23-2008 07:19 PM
JSP and Javascripts on same page (Passing values to JSP fromJavascript) Husain Javascript 3 04-14-2008 10:36 AM
[JSP] difference between jsp:forward and jsp:include alexjaquet@gmail.com Java 0 06-02-2006 01:21 PM
<%JSP:include page="hello.jsp" %> Shinya Koizumi Java 3 03-12-2006 11:34 PM
How to get the html output of a local JSP page from my Java code, or use a JSP as an HTML templates. DigitalUncle Java 0 11-02-2004 05:22 PM



Advertisments