every variable declared in the declaration tag

<%! .... %> is a class level variable... that means its going to be shared
by all the threads, u might have some volatile data, unless u synchronize
it...

just declare ur variables within a scriplet tag

<% .. %>

with out the " ! ".....

hope that helps

Amit

-----Original Message-----
From: A mailing list about Java Server Pages specification and reference
[mailto:JSP-INTEREST@;JAVA.SUN.COM]On Behalf Of Daniel
Sent: Wednesday, November 13, 2002 2:33 AM
To: [EMAIL PROTECTED]
Subject: Thread Doubt and Multi User Environment


Hi,

I have a JSP code like this and this is converted into a servlet. What
happens when multiple user tries to access the code, I have written the
jsp code down and the servlet equivalent is also given. Is it a bad to
write the variables as private. What happens when multiple user try to
access the same jsp page.


Is it safe for multi user environment?

Is it really a bad code for multi user environment? Since the variables
are declared private!


Regards,
Daniel.E

/*********************JSP code
******************************************/



<%

  try {

  //Get session variable and check authorization
  Integer n_user_id = (Integer)session.getAttribute("n_user_id");
  Integer n_group_id = (Integer)session.getAttribute("n_group_id");

  if(n_user_id == null || n_group_id.intValue() != 1) {
    response.sendRedirect("../../../login/index.jsp");
    return;
  }

  } catch(Exception e) {
      response.sendRedirect("../../../login/index.jsp");
      return;
  }

%>

<HTML>
<HEAD>
  <meta http-equiv="Content-Type" content="text/html;
charset=Shift_JIS">
  <link rel="stylesheet" href="../../../../stylesheet/styleMori.css"
type="text/css">
  <TITLE>New User</TITLE>
</HEAD>
<BODY>

<%@ page language="java" contentType ="text/html;charset=Shift_JIS" %>

<!-- All imports used in this JSP file -->

<%@page import="java.sql.DriverManager" %>
<%@page import="java.sql.Connection" %>
<%@page import="java.sql.PreparedStatement" %>
<%@page import="java.sql.Statement" %>
<%@page import="java.sql.ResultSet" %>

<%@page import="java.io.StringWriter" %>
<%@page import="java.io.PrintWriter" %>

<%@page import="com.mustang.dbutil.DbConnection" %>

<%@page import="com.mustang.sqlutil.SQLParam" %>

<!-- Variables Declaration -->
<%! private String loginid = null; %>
<%! private String pass = null; %>
<%! private String fname = null; %>
<%! private String gname = null; %>
<%! private String email = null; %>
<%! private String access_level = null; %>

<%! private int access = 0; %>

<%! private StringWriter sw = new StringWriter(); %>
<%! private PrintWriter pw = new PrintWriter(sw); %>

<%! private DbConnection db = null; %>

<%! private Connection con = null; %>
<%! private PreparedStatement pstmt = null; %>
<%! private Statement stmt = null; %>
<%! private ResultSet res = null; %>

<%

  //aquire variables
  try {
    access = Integer.parseInt(request.getParameter("access"));

    loginid = request.getParameter("loginid");
    pass = request.getParameter("pass");
    fname = request.getParameter("fname");
    gname = request.getParameter("gname");
    email = request.getParameter("email");

    if(loginid == null || pass == null
      || request.getParameter("access") == null
      || fname == null || gname == null || email == null) {

/********************************Servlet Code ******************/

package org.apache.jsp;

import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.Statement;
import java.sql.ResultSet;
import java.io.StringWriter;
import java.io.PrintWriter;
import com.mustang.dbutil.DbConnection;
import com.mustang.sqlutil.SQLParam;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.jsp.*;
import org.apache.jasper.runtime.*;


public class newUserProcessAd$jsp extends HttpJspBase {

    // begin
[file="/jspsource/admin/user/newuser/newUserProcessAd.jsp";from=(61,3);t
o=(61,35)]
         private String loginid = null;
    // end
    // begin
[file="/jspsource/admin/user/newuser/newUserProcessAd.jsp";from=(62,3);t
o=(62,32)]
         private String pass = null;
    // end
    // begin
[file="/jspsource/admin/user/newuser/newUserProcessAd.jsp";from=(63,3);t
o=(63,33)]
         private String fname = null;
    // end
    // begin
[file="/jspsource/admin/user/newuser/newUserProcessAd.jsp";from=(64,3);t
o=(64,33)]
         private String gname = null;
    // end
    // begin
[file="/jspsource/admin/user/newuser/newUserProcessAd.jsp";from=(65,3);t
o=(65,33)]
         private String email = null;
    // end
    // begin
[file="/jspsource/admin/user/newuser/newUserProcessAd.jsp";from=(66,3);t
o=(66,40)]
         private String access_level = null;
    // end
    // begin
[file="/jspsource/admin/user/newuser/newUserProcessAd.jsp";from=(68,3);t
o=(68,28)]
         private int access = 0;
    // end
    // begin
[file="/jspsource/admin/user/newuser/newUserProcessAd.jsp";from=(70,3);t
o=(70,50)]
         private StringWriter sw = new StringWriter();
    // end
    // begin
[file="/jspsource/admin/user/newuser/newUserProcessAd.jsp";from=(71,3);t
o=(71,50)]
         private PrintWriter pw = new PrintWriter(sw);
    // end
    // begin
[file="/jspsource/admin/user/newuser/newUserProcessAd.jsp";from=(73,3);t
o=(73,36)]
         private DbConnection db = null;
    // end
    // begin
[file="/jspsource/admin/user/newuser/newUserProcessAd.jsp";from=(75,3);t
o=(75,35)]
         private Connection con = null;
    // end
    // begin
[file="/jspsource/admin/user/newuser/newUserProcessAd.jsp";from=(76,3);t
o=(76,44)]
         private PreparedStatement pstmt = null;
    // end
    // begin
[file="/jspsource/admin/user/newuser/newUserProcessAd.jsp";from=(77,3);t
o=(77,35)]
         private Statement stmt = null;
    // end
    // begin
[file="/jspsource/admin/user/newuser/newUserProcessAd.jsp";from=(78,3);t
o=(78,34)]
         private ResultSet res = null;
    // end

    static {
    }
    public newUserProcessAd$jsp( ) {
    }

    private static boolean _jspx_inited = false;

    public final void _jspx_init() throws
org.apache.jasper.runtime.JspException {
    }

    public void _jspService(HttpServletRequest request,
HttpServletResponse  response)
        throws java.io.IOException, ServletException {

        JspFactory _jspxFactory = null;
        PageContext pageContext = null;
        HttpSession session = null;
        ServletContext application = null;
        ServletConfig config = null;
        JspWriter out = null;
        Object page = this;
        String  _value = null;
        try {

            if (_jspx_inited == false) {
                synchronized (this) {


/********************************Servlet Code ******************/

===========================================================================
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://archives.java.sun.com/jsp-interest.html
 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.jsp
 http://www.jguru.com/faq/index.jsp
 http://www.jspinsider.com

===========================================================================
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://archives.java.sun.com/jsp-interest.html
 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.jsp
 http://www.jguru.com/faq/index.jsp
 http://www.jspinsider.com

Reply via email to