Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

weather i have to use this or not

 
deepak singh
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi ,
i am making an portal in servlet i am using global variable,like for example
-----------------------------------------------------
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import java.lang.*;
import javax.naming.*;
import java.sql.*;
import java.net.*;
import cpool.*;
public class AdminSearch extends HttpServlet {
String login;
String password;
String userType;

String firstName;
String lastName;
String address;
String city;
String state;
String zip;
String country;
String email;
String phone;
String specialty;
String status;
String sort;
String num;
boolean notFound= true ;
private Connection conn=null;
public void setConnection(Connection conn)
{
this.conn=conn;
}
public Connection getConnection()
{
return this.conn;
}

/** Initializes the servlet.
*/
public void init(ServletConfig config) throws ServletException {
super.init(config);
}
/** Destroys the servlet.
*/
public void destroy() {
}

/** Handles the HTTP <code>GET</code> method.
* @param request servlet request
* @param response servlet response
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, java.io.IOException {
doPost(request,response);
}

/** Handles the HTTP <code>POST</code> method.
* @param request servlet request
* @param response servlet response
*/

protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, java.io.IOException {
---
--
codind
---
--
}
-------------------------------------------------------
will this affect any way to site .
thanx
deepak
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you have global variables in Servlets and don't implement the SingleThreadModel you get 'unforseen errors'.
Have a read of this at jguru or this at the same place, which describes how to make a srevlet thread safe and the life cycle of a servlet.
Enjoy,
Dave.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic