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 Browser calls servlet twice (iE) 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 "Browser calls servlet twice (iE)" Watch "Browser calls servlet twice (iE)" New topic
Author

Browser calls servlet twice (iE)

rich werth
Ranch Hand

Joined: Sep 21, 2001
Posts: 57
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

Joined: May 10, 2001
Posts: 3244
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?


Dave
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

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

Joined: Feb 20, 2001
Posts: 3695

would this be fixed by having the method return false? as you might tell, javascript is not my thing.
Eric Lim
Greenhorn

Joined: Apr 01, 2002
Posts: 19
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Browser calls servlet twice (iE)