JSP functions/methods page question

Discussion in 'Java' started by johnston_58@hotmail.com, Jan 28, 2005.

  1. Guest

    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
    , Jan 28, 2005
    #1
    1. Advertising

  2. Last Timer Guest

    Last Timer, Jan 28, 2005
    #2
    1. Advertising

  3. <> 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
    Heiner Kücker, Jan 29, 2005
    #3
  4. Nick Guest

    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.
    Nick, Jan 29, 2005
    #4
  5. Guest

    Hi,

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

    and this is working great.

    Thanks again,
    J
    , Jan 29, 2005
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. DigitalUncle
    Replies:
    0
    Views:
    875
    DigitalUncle
    Nov 2, 2004
  2. Shinya Koizumi

    <%JSP:include page="hello.jsp" %>

    Shinya Koizumi, Mar 9, 2006, in forum: Java
    Replies:
    3
    Views:
    9,626
    Raymond DeCampo
    Mar 12, 2006
  3. Xiangliang Meng
    Replies:
    1
    Views:
    1,568
    Victor Bazarov
    Jun 21, 2004
  4. Replies:
    0
    Views:
    4,313
  5. Kenneth McDonald
    Replies:
    5
    Views:
    287
    Kenneth McDonald
    Sep 26, 2008
Loading...

Share This Page