This week's book giveaway is in the Artificial Intelligence forum.
We're giving away four copies of Pragmatic AI and have Noah Gift on-line!
See this thread for details.
Win a copy of Pragmatic AI this week in the Artificial Intelligence forum!

Phil Hanna

Ranch Hand
+ Follow
since Apr 05, 2001
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 Phil Hanna

No, you cannot use the same session for both http and https URL's. See HttpResponseBase.java in the Tomcat 4 source code, specifically the isEncodeable() method. The URL's in a session must match down to and including the servlet context. It explicitly checks both URL's with getScheme(), which will be different in the case you mention.
16 years ago
JSP's cannot write binary data to the response output stream, either directly or by calling <jsp:include>. The JSP specification explicitly forbids it. The reason for this is that the JSP container automatically initializes the "out" implicit variable with response.getWriter(). If you look at the API documentation for javax.servlet.ServletResponse, you'll note that you can call either getWriter() or getOutputStream(), but not both.
Tomcat defers opening the JspWriter "out" object until you actually write a character, but it will still probably throw an IllegalStateException when it does.
You can write a binary output stream from a servlet, exactly as you have described, but not from a JSP (at least not reliably). If you need to use the JSP as the front end to the application, then use response.sendRedirect("the servlet URL") instead of <jsp:forward>. That will cause the client browser to initiate an additional request, which will not comingle the character and binary output.
------------------
Phil Hanna
Sun Certified Programmer for the Java 2 Platform
Author of :
JSP: The Complete Reference
Instant Java Servlets
[This message has been edited by Phil Hanna (edited August 25, 2001).]
17 years ago
request.getCookies() returns only the cookies sent with this particular request, not every cookie on the user's machine.
------------------
Phil Hanna
Sun Certified Programmer for the Java 2 Platform
Author of :
JSP: The Complete Reference
Instant Java Servlets
17 years ago
Yes, but it's almost always a poor design to do this. Why do you need instance variables to be persistent? An HTTP session is a much cleaner way to do this. SingleThreadModel does not scale well.
------------------
Phil Hanna
Sun Certified Programmer for the Java 2 Platform
Author of :
JSP: The Complete Reference
Instant Java Servlets
17 years ago
In your applet, use:
getAppletContext().showDocument(nextURL)

------------------
Phil Hanna
Sun Certified Programmer for the Java 2 Platform
Author of :
JSP: The Complete Reference
Instant Java Servlets
17 years ago
You obviously have an older version of servlet.jar still in your classpath.
With Java 2, you should never use the CLASSPATH environment variable. Delete it from your autoexec.bat. Always use the -cp or -classpath command line option:
javac -classpath .;path/servlet.jar MyContextListener.java
Also check to make sure the servlet.jar file is not in your JDK\JRE\lib\ext directory - that will take precedence over anything you specify in the classpath.
------------------
Phil Hanna
Sun Certified Programmer for the Java 2 Platform
Author of :
JSP: The Complete Reference
Instant Java Servlets
17 years ago
In your web.xml file, did you put the <init-param> blocks inside a <servlet> block?
------------------
Phil Hanna
Sun Certified Programmer for the Java 2 Platform
Author of :
JSP: The Complete Reference
Instant Java Servlets
17 years ago
It is the browser, not the server, which controls the creation of frames. The server doesn't know anything about them. All it does is respond to individual HTTP requests for pages and return them to the client that requested them.
If you want JSP output to appear in a frame, you need to have the URL that the client clicks specify a frame target. Remember that forward() is entirely a server-side operation; the browser is unaware of it.

------------------
Phil Hanna
Sun Certified Programmer for the Java 2 Platform
Author of :
JSP: The Complete Reference
Instant Java Servlets
17 years ago
If you are behind a firewall, you need to define some system properties that point to your proxy:
System.setProperty("http.proxyHost", "myproxy.myserver.com");
System.setProperty("http.proxyPort", "80");
System.setProperty("http.proxySet", "true");
Note that this works for URLConnection access, but not plain sockets.
------------------
Phil Hanna
Sun Certified Programmer for the Java 2 Platform
Author of :
JSP: The Complete Reference
Instant Java Servlets
17 years ago
You pass init parameter to a JSP the same as a servlet, using the web.xml deployment descriptor. The key is using the <jsp-file> element instead of <servlet-class>:
<servlet>
<servlet-name>foo</servlet-name>
<jsp-file>myFile.jsp</jsp-file>
<init-param>
<param-name>flavor</param-name>
<param-value>vanilla</param-value>
</init-param>
</servlet>
Note, however, that you need to call the JSP by its servlet name, which would be %WEBAPPNAME%/servlet/foo, in the case above. If you don't, the servlet engine will not be aware that you are using the <servlet> element with its init parameters.
You can additionally supply a servlet mapping if you still want to use a "jsp" name:
<servlet-mapping>
<servlet-name>foo</servlet-name>
<url-pattern>myFile.jsp</url-pattern>
</servlet-mapping>
If you've never read the JSP specification or the DTD, it can be of great help to you.

------------------
Phil Hanna
Sun Certified Programmer for the Java 2 Platform
Author of :
JSP: The Complete Reference
Instant Java Servlets
17 years ago
You aren't showing the code that gets the exception. You've created a result set (rs) but you're probably trying to access it elsewhere. If you haven't called rs.next(), that's the problem.
BTW, your executeQuery() method doesn't declare the rs variable. If you're declaring it as an instance variable in the servlet, you've got problems. Servlets are multithreaded, and if two requests occurs at or about the same time, the second one will overlay the instance variables of the first. Don't use instance variables; either keep the variables local to a method, or save them in an HttpSession object.

------------------
Phil Hanna
Sun Certified Programmer for the Java 2 Platform
Author of :
JSP: The Complete Reference
Instant Java Servlets
17 years ago
A servlet is no different in this respect than any other Java class. You can use the delete() method in the java.io.File class:
File myFile = new File("c:/whatever/somefile");
myFile.delete();
------------------
Phil Hanna
Sun Certified Programmer for the Java 2 Platform
Author of :
JSP: The Complete Reference
Instant Java Servlets
17 years ago
The HTML 4.01 specification suggests using the "title" attribute in the link:
<a href="http://www.ibm.com" title="Big Blue">IBM</a>
This works in Internet Explorer 5.5: if you move the mouse over the link and stop, it displays the title text in a popup. Netscape 4.75 doesn't appear to do anything with it.
------------------
Phil Hanna
Sun Certified Programmer for the Java 2 Platform
Author of :
JSP: The Complete Reference
Instant Java Servlets
17 years ago
Why would you think Integer.toString(i) is not threadsafe? It does not access anything but its own local variables.
Most often, I use String.valueOf(i).
------------------
Phil Hanna
Sun Certified Programmer for the Java 2 Platform
Author of :
JSP: The Complete Reference
Instant Java Servlets
17 years ago
You say the error begins at the first uncommented line of server.xml. Why not post the file so somebody can look at it?
------------------
Phil Hanna
Sun Certified Programmer for the Java 2 Platform
Author of :
JSP: The Complete Reference
Instant Java Servlets
17 years ago