This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Servlets and the fly likes weather i have to use this or not Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "weather i have to use this or not" Watch "weather i have to use this or not" New topic
Author

weather i have to use this or not

deepak singh
Greenhorn

Joined: Sep 03, 2001
Posts: 4
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

Joined: Mar 06, 2001
Posts: 13459

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: weather i have to use this or not