You can create a function a JSP . JSP gets converted by the JSP container into a
java file and compiled into a class file. The JSP is converted into a class and
not a function. So if you have a function in your JSP  it becomes a part of the
CLASS and NOT FUNCTION.

Here is an JSP code snippet and its corresponding generated class.The function
doLogin gets included as a function
in the generated class jrun__2e__login2ejspc.


JSP Code
<%@ include file="include/login_inc.jsp" %>
<%
String szError = new String("");
String USER_ID = (String)request.getParameter("UserID");
String PASSWORD = (String)request.getParameter("Password");

if (USER_ID != null) {
     if(doLogin(USER_ID, PASSWORD, session) == SUCCESS){
          response.sendRedirect(returnMsg);
     } else {
          szError = returnMsg;
     }
}
%>
<html>
<head>
</head>

JSP Code from included file login_inc.jsp
<%@ page import="java.sql.*"%>
<%!
public int doLogin(String USER_ID, String PASSWORD, HttpSession session)
{
     ResultSet rs;
     Statement stmt;
     Connection dbConn;

     try {
          Class.forName("oracle.jdbc.driver.OracleDriver");
          dbConn = DriverManager.getConnection(database, userid, password);

     }

     catch(Exception e) {
          returnMsg = "doLogin: " + e.getMessage();
          return FAILURE;
     }
}
%>



Generaed JAVA Code
// Generated by JRun, do not edit


import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
import allaire.jrun.jsp.JRunJSPStaticHelpers;

/*##E:\\benefacts\\TR\\dev\\login.jsp##*/
/*#1#1#*/import java.sql.*;public class jrun__2e__login2ejspc extends
allaire.jrun.jsp.HttpJSPServlet implements allaire.jrun.jsp.JRunJspPage
{
    private ServletConfig config;
    private ServletContext application;
    private Object page = this;
    private JspFactory __jspFactory = JspFactory.getDefaultFactory();

    public void _jspService(HttpServletRequest request, HttpServletResponse
response)
         throws ServletException, java.io.IOException
    {
        if(config == null) {
            config = getServletConfig();
            application = config.getServletContext();
        }
        response.setContentType("text/html; charset=ISO-8859-1");
        PageContext pageContext = __jspFactory.getPageContext(this, request,
response,  null, true, 8192, true);
        JspWriter out = pageContext.getOut();
        HttpSession session = pageContext.getSession();

        try {
/*##E:\\benefacts\\TR\\dev\\include\\login_inc.jsp##*/out.print("\r\n");

/*#3#11#*/String szError = new String("");
String USER_ID = (String)request.getParameter("UserID");
String PASSWORD = (String)request.getParameter("Password");

if (USER_ID != null) {
     if(doLogin(USER_ID, PASSWORD, session) == SUCCESS){
          response.sendRedirect(returnMsg);
     } else {
          szError = returnMsg;
     }
}

        } catch(Throwable t) {
            if(t instanceof ServletException)
                throw (ServletException) t;
            if(t instanceof java.io.IOException)
                throw (java.io.IOException) t;
            if(t instanceof RuntimeException)
                throw (RuntimeException) t;
            throw JRunJSPStaticHelpers.handleException(t, pageContext);

        } finally {
            __jspFactory.releasePageContext(pageContext);
        }
    }

public int doLogin(String USER_ID, String PASSWORD, HttpSession session)
{
     ResultSet rs;
     Statement stmt;
     Connection dbConn;

     try {
          Class.forName("oracle.jdbc.driver.OracleDriver");
          dbConn = DriverManager.getConnection(database, userid, password);
        }

      catch(Exception e) {
          returnMsg = "doLogin: " + e.getMessage();
          return FAILURE;
     }
}
}


Santosh









Miihir Sahu <[EMAIL PROTECTED]> on 08/29/2001 11:18:01 AM

Please respond to A mailing list about Java Server Pages specification and
      reference <[EMAIL PROTECTED]>

To:   [EMAIL PROTECTED]
cc:    (bcc: Santosh Daryani/IT/Aon Consulting)

Subject:  Re: Creating a JSP function



Hi,
    As far as I know, we cannot have a function in JSP.  This is due to
the fact that whatever we are writing in the JSP is combined into a
function in a servlet.  So if we are to write JSP function, that means
function within a function, whichi is not possible....this is what I
know from the knowledge of JSP.  If anyone has really done it, please do
inform me, as I think it is a really a surprise to me.  Thanks
Regards
Mihir

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

Reply via email to