Barron Greig

Greenhorn
+ Follow
since Jan 26, 2002
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Barron Greig

Hello all,
I have a servlet that generates JPEG with hardcoded dimensions. What I'd really like though is to somehow pass details of the browser window width and height to the servlet so that it generates an image exactly that size. Also, if the user resized the window, then I'd send back a new image with the correct dimensions.
Any ideas how I'd do this?
Thanks in advance,
Barry
21 years ago
I don't know anything about Websphere but is it possible you are storing information on the threads in some global collection and not removing the entry for a thread when it dies, so it never gets garbage collected.
Is there a compact piece of code you could post that would show the essence of how you are tallying the threads?
22 years ago
Assuming you have a Connection object "con", you can create statement, e.g.
PreparedStatement stmt = con.prepareStatement("SELECT * FROM EMPLOYEES");
executing that statement returns a ResultSet which you can then iterate over. I guess the ResultSet is probably using a cursor somewhere deep down in the implementation
ResultSet rs = stmt.executeQuery();
while (rs.next()) {
.. rs.getXXX methods to retrieve field info from
each ResultSet result.
}
22 years ago
The servlet engine is doing all the hard work of maintaining the session for you using either cookies or URL rewriting. The maxInactiveInterval (defaults to 20 minutes) will mean that if the client doesn't send another request for 20 minutes, the servlet engine is free to expire that session. If you have high demand then you might end up with a build up of "stale" sessions. You could shorten the interval, but take into account that if the interval was a few seconds, then every time they paused to think, their session would time-out on them. If you don't have high demand you could maybe make the maxInactiveInterval longer so they could go away and cook their dinner before completing purchase of Widgets from your online store.
If you do change maxInactiveInterval, I recommend changing it in the web.xml. There is a <session-config> parameter called <session-timeout> that will have the same effect.
22 years ago
1. The session object is created behind the scenes when that client makes its first request. getSession() is just getting a handle onto the already existing session object.
2. If you are authenticating the user via one of the techniques in the Java Servlet spec (e.g. HTTP basic, digest, form) then you can use the method HttpRequest.getRemoteUser() to get the name of the user that was logged in and use that to look up your database of profile information.
22 years ago
I don't think there is a way of passing frame info directly to the HttpServletResponse. You do have to use a bit of Javascript. I wrote a support method for loading into a frame from servlet code. It's used something like
reloadFrame(response, "/myapp/Target.jsp");
In my code, the frame MUST have been given the same name as the jsp file without extension. For the above example, the frame could have been declared something like
<IFRAME name="Target" SRC="/myapp/Target.jsp"
scrolling=no></IFRAME>
The method itself:
protected void reloadFrame(HttpServletResponse response,
String frameURL)
throws IOException {
ServletOutputStream out = response.getOutputStream();
String frameName = (new File(frameURL)).getName();
StringTokenizer stok = new StringTokenizer(frameName, ".");
frameName = stok.nextToken();
out.println("<HTML><BODY>");
out.println("<SCRIPT LANGUAGE=\"JavaScript\">");
out.println("<!--");
out.println("frs = top.frames");
out.println("for (i = 0;i < frs.length;i++) {");
out.println(" if (frs[i].name == \"" + frameName + "\") {");
out.println(" top.frames[i].location.href=\"" + frameURL + "\"");
out.println(" break");
out.println(" }");
out.println("}");
out.println("// -->");
out.println("</SCRIPT>");
outputNoScript(out);
out.println("</BODY></HTML>");
}
22 years ago
The server does not know if the browser has been closed. The session will stay alive until the servlet engine is shut down.
22 years ago