Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Browser calls servlet twice (iE)

 
rich werth
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello there....
I am having strange results when I call a servlet.
When I call the servlet with Netscape(4.77) Everything seems to be working fine.
When I call the servlet with IE(6.0.26) It calls the servlet twice.
Here is the code of my servlet:
Do get and do post simply call this method.
public void checkInfo(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.
HttpServletResponse response) throws javax.
servlet.ServletException, java.io.IOException {
HttpSession session = request.getSession(true);
try {
if (session.isNew()) {
id = request.getParameter("id");
session.setAttribute("userID", id);
db.setId(id);
pass = request.getParameter("pass");
db.setPass(pass);
getServletContext().setAttribute("conPool", ds);
db.setDs(ds);
rs = db.checkLogon();
Calendar calendar = Calendar.getInstance();
String months[] = {
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9",
"10",
"11",
"12"
};
int day = calendar.get(Calendar.DATE);
String month = (months[calendar.get(Calendar.MONTH)]);
int year = calendar.get(Calendar.YEAR);
String theDate = month + "/" + day + "/" + year;
if (rs.next()) {
userVec.addElement(rs.getString(1));
System.out.println("added 1");
userVec.addElement(rs.getString(2));
System.out.println("added 2");
userVec.addElement(rs.getString(3));
System.out.println("added 3");
userVec.addElement(rs.getString(4));
System.out.println("added 4");
userVec.addElement(rs.getString(5));
System.out.println("added 5");
userVec.addElement(rs.getString(6));
System.out.println("added 6");
userVec.addElement(theDate);
System.out.println("added date");
session.setAttribute("userData", userVec);
rs.close();
}
else {
response.sendRedirect("incorrect_info.html");
session.invalidate();
}
}
if (!(userVec.isEmpty())) {
sessionVector = (Vector) session.getAttribute("userData");
role = (String) sessionVector.elementAt(2);
int i;
for (i = 0; i < sessionVector.size(); i++) {
System.out.println("Vector item " + i + ":" + " is: " + sessionVector.elementAt(i));
}
if (role.equals("a")) {
getServletContext().getRequestDispatcher(
"/mainMenu.jsp").forward(request, response);
}
else if (role.equals("u")) {
getServletContext().getRequestDispatcher(
"/mainMenuAP.jsp").forward(request, response);
}
}
}
catch (Exception e) {
e.printStackTrace();
}
}
 
Dave Vick
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rich
What does the code on the calling page look like? Do you have any javascript that is maybe submitting it and also through a submit button?
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah, I did the same thing once.
I had something like this:

(Note that the on_Click is a deliberate typo..._
Dave
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
would this be fixed by having the method return false? as you might tell, javascript is not my thing.
 
Eric Lim
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rich
I have encountered similar problem as well. In my case, I have isolated the problem only to a GET request. It doesn't happen in a POST, not even in IE.
I'm not sure if we have the same situation but I hope this helps.
Eric
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic