Win a copy of Spring Boot in Practice this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

Servlet Session + have not Clue....HELP....PLEASE...

 
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
THis is what i had created, a servlet project using Jbuilder 7 and TomCat 4.0 that get Images from DB and displays it on the
Browser depending on what documentType the user selected....
If i run the Tom-cat on my machine and then run my project, It runs fine...
If i goto another machine and run my project, i get Two different frames one from my machine that has Tom-Cat running
and another one from the new new machine....
I need to Create a session for each user....
The problem is I am not familiar with Sessions.. I searched on Internet for examples but i got more confused.
I would appreciate if you can point me on right direction.....
================================================================
I am posting my Code....
========================

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2003</p>
* <p>Company: </p>
* @author unascribed
* @version 1.0
*/
public class Servlet1 extends HttpServlet implements java.io.Serializable {
static final private String CONTENT_TYPE = "text/html";
private String dbDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
private String dbURL = "jdbc dbc:SCANODBC_LIVE";
private String userid = "SYSDBA";
private String passwd = "masterkey";
private String nextLine = "\n";
private String fx = null;
private String lx = null;
private String dx = null;
private String sx = null;
private String px = null;
private String mx = null;
private String pidx = null;
private String policyNumber = null;
private String pid = null;
private String firstName = null;
private String lastName = null;
private String SSN = null;
private String MI = null;
private String index = null;
StringBuffer outputOfImageScreen = new StringBuffer();
private int k;
private int id;
public DatabaseAccessor databaseAccessor = null;
CreateScript createScript = new CreateScript();
//Initialize global variables

public void init(ServletConfig config) throws ServletException {
super.init(config);
System.out.println("DBServlet init: Start");
String value = null;
// read in parameter value for dbDriver
if ( (value = config.getInitParameter("dbDriver")) != null )
{
dbDriver = value;
}
// read in parameter value for dbDriver
if ( (value = config.getInitParameter("dbURL")) != null )
{
dbURL = value;
}
// read in parameter value for used id
if ( (value = config.getInitParameter("userid")) != null )
{
userid = value;
}
// read in parameter value for dbDriver
if ( (value = config.getInitParameter("passwd")) != null )
{
passwd = value;
}
databaseAccessor = new DatabaseAccessor(dbDriver, dbURL, userid, passwd);
log("Database Connection...");
}
//Process the HTTP Get request
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter();
/*
HttpSession session = request.getSession(true);
Date created = new Date(session.getCreationTime());
Date accessed = new Date(session.getLastAccessedTime());
out.println("ID " + session.getId());
out.println("Created: " + created);
out.println("Last Accessed: " + accessed);
*/
// creates the Search Form
out.println(createScript.createSearchForm());
}
//Process the HTTP Post request
public void doPost(HttpServletRequest request, HttpServletResponse res)
throws IOException, ServletException
{
String xParameterName = null;
String xParameterValue = null;
PrintWriter out = res.getWriter();
Enumeration e = request.getParameterNames();

while (e.hasMoreElements()) {
xParameterName = (String) e.nextElement();
xParameterValue = request.getParameter(xParameterName);

if ((xParameterValue.trim().length() !=0 )){
if(xParameterName.compareTo("firstnameTextfield")==0){
}
else if(xParameterName.compareTo("lastnameTextfield")==0){
}
else if(xParameterName.compareTo("policynumberTextfield")==0){
StringBuffer outstring = new StringBuffer();
outstring.append(createScript.policyReCreateSearchForm(xParameterValue));
outstring.append(createScript.setTopPart());
outstring.append(createScript.getHeader());

Vector policyInformationVector1 = getPolicyInformation(res, xParameterValue);
Iterator iter = policyInformationVector1.iterator();
PolicyInformation aPolicyInformation = null;
while(iter.hasNext()){
Object[] data = new String[policyInformationVector1.size()];
for (int ii=0; ii < data.length; ii++){
int rowNum = ii + 1;
aPolicyInformation = (PolicyInformation) iter.next();
fx = aPolicyInformation.getFirstName();
lx = aPolicyInformation.getLastName();
dx = aPolicyInformation.getDOB();
sx = aPolicyInformation.getSSN();
px = aPolicyInformation.getPolicyNumber();
mx = aPolicyInformation.getMiddleName();
pidx = aPolicyInformation.getPid();
outstring.append(createScript.setRowValue(fx,mx,lx,px,pidx,dx,sx,rowNum));
outstring.append(createScript.setRowValue1());
}
}
outstring.append(createScript.getBottom());
out.println(outstring.toString());
}
else if(xParameterName.compareTo("ssnTextfield")==0){
}
}
// gets the PID
if(xParameterName.compareTo("pid") == 0){
pid = request.getParameter("pid");
policyNumber = request.getParameter("policyNumber");
firstName = request.getParameter("firstName");
lastName = request.getParameter("lastName");
SSN = request.getParameter("ssn");
MI = request.getParameter("mi");
Vector documentInformationVector = databaseAccessor.getDocumentInformation(pid,policyNumber);
Iterator iter = documentInformationVector.iterator();
DocumentInformation documentInformation = null;
outputOfImageScreen.append(createScript.createTopPartOfZoomScript());
outputOfImageScreen.append(createScript.createZoomLabels());
outputOfImageScreen.append(createScript.startOfDocumentList());
while(iter.hasNext()){
Object[] data = new String[documentInformationVector.size()];
for (int ii=0; ii < data.length; ii++){
documentInformation = (DocumentInformation) iter.next();
String docType = documentInformation.getDocumentType();
int uindex = documentInformation.getUindex();
int pindex = documentInformation.getPIndex();
if(uindex != 0){
outputOfImageScreen.append(createScript.insertDocumentTypeToListUindex(docType, uindex));
}
else{
outputOfImageScreen.append(createScript.insertDocumentTypeToListPindex(docType, pindex));
}
}
}
outputOfImageScreen.append(createScript.endOfWholeZoomScreen());
out.println(outputOfImageScreen.toString());
}
if(xParameterName.compareTo("index") == 0){
String indexValue = null;
index = request.getParameter("index");
if(index.startsWith("pindex")){
indexValue = index.substring(7);
databaseAccessor.getImageFromPolicy(indexValue);
}
else{
indexValue = index.substring(6);
databaseAccessor.getImageFromUnmatch(indexValue);
}
out.println(outputOfImageScreen.toString());
}
} // end of while(e.hasMoreElements())
}
//getPolicyInformation
protected Vector getPolicyInformation(HttpServletResponse response,String xParameterValue){
Vector policyInformationVector = databaseAccessor.getPolicyInformation(xParameterValue);
return policyInformationVector;
}

//Clean up resources
public void destroy() {
}

}
 
reply
    Bookmark Topic Watch Topic
  • New Topic