Win a copy of JDBC Workbook this week in the JDBC and Relational Databases forum
or A Day in Code in the A Day in Code forum!

Christopher Dixon

Greenhorn
+ Follow
since Jan 30, 2002
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 Christopher Dixon

Hello all,
Why don't interfaces support static final method declarations? I've been looking around, and I see plenty of explanations that just point to the JLS and say 'because'. Can anyone help me with why?
Abstract classes support static method declarations.
Interfaces support field declarations which are exposed as static final fields.
Static final methods in interfaces could be bound at compile time (like any other static method) and the compiler could complain about ambigous references (like it does with final static fields).
I'm not looking for a new JSR, but I searched and couldn't find an explanation. Any thoughts?
Thanks,
Chris
16 years ago

Of all the many things affecting performance in Servlets, the session mechanism is probably the least important.


I think the specifics of the in-memory mechanism itself aren't very important, but being aware of the volume/frequency of session updates by the application is critical for scalability.
It is especially important for a cluster, where agressive session persistance settings in the container config may cause modifcations to the session to persist directly to a datasource.
These concerns are probably more architectural than impementation, but everyone along the way should be aware.
JMHO,
Chris
[ April 06, 2003: Message edited by: Christopher Dixon ]
[ April 06, 2003: Message edited by: Christopher Dixon ]
17 years ago
This isn't the most elegant solution, but if I understand your requirements correctly:
  • You want the file to open in the users browser, not prompt for 'save' or 'open'.
  • You the browser to recognize the page's file name as something you set.
  • I've had cross-browser problems with quite a few of the HTTP headers, so you're not alone.
    What if you mapped a servlet url-pattern to the beginning of the directory, say ? The browser only cares about the last segment of the URL, so make it whatever you want, but route based on the mapping. So, if you were creating a list of invoices, you could link to . The showInvoice servlet (or JSP) could either perform business logic and stream the content back, or just be a front end controller.
    If you needed to set this at request processing time (as opposed to at link-creation time, the request before), you could use sendRedirect(), but you would need to either store in session or pass in the request any data that you wanted to keep.
    hth,
    Chris
    [ March 19, 2003: Message edited by: Christopher Dixon ]
    [ March 19, 2003: Message edited by: Christopher Dixon ]
    17 years ago
    A NoSuchMethodError is the runtime equivalent of getting a 'Method not found' error from the compiler.
    Any time I've had this problem is was from compiling in one location, and deploying into another.
    If the class files in your compiler classpath are up to date, but your runtime isn't, this could happen. Also check the ordering of the elements in the classpath. The classloader may choose any version it happens to run across(How the Java Launcher Finds Classes)
    I think that any other types of unresolved method or field calls would result in a more specific exception, like an InvocationTargetException for a bad reflective call or a standard compile error if your binaries were out of date.
    HTH,
    Chris
    17 years ago
    If you just want to include it in a page the servlet is generating, look at Request.getRequestDispatcher(String).include()
    To capture the code, either wrap the Request in a proxy that writes to your own Writer or OutputStream, or look at servlet filtering.
    If you're trying to screen scrape, there are lots of packages out there to do it (check out Struts), or you can open a java.net.URL and do it the hard way.
    Google is the Oracle. Ask and ye shall receive.
    Chris
    [ October 28, 2002: Message edited by: Christopher Dixon ]
    17 years ago
    The JDBC drivers for most databases (Oracle, DB2, SQLServer, etc) are notoriously horrible at giving error messages. You're usually much better off (if you can) to look in the server logs. If you're using type 2 drivers (like the oracle OCI or DB2Connect), you can also turn up the client side logging and get more info. If you can't get to the logs, poke and hope, like Michael said.
    HTH,
    Chris
    Yes. You can place the .jar files in the /lib/ext directory of the JRE, ie c:\jdk1.4\jre\lib\ext. There are a couple of caveats to this, though:
  • Some compilers may not pick up the .jar files. If this is the case and you have a bunch of .jar files, look into scripting or using a build tool like ant
  • The files you place into this directory will load with higher permissions than files loaded by a delegated classloader.
  • If you're using an application container (like Tomcat, JBoss, Websphere, etc),some .jar files (Struts is first to come to mind) must be loaded for each web application seperately. They should not be placed in /jre/lib/ext. They would normally say this in the documentation.

  • If you're interested in why, check out:
    How the classloader works
    HTH,
    Chris
    [ October 27, 2002: Message edited by: Christopher Dixon ]
    [ October 27, 2002: Message edited by: Christopher Dixon ]
    17 years ago
    Does it serve static content, or JSP, from /RnD/ ?
    If so, the only thing I could suggest would be double check the declaration in server.xml. It has to be well formed, since you didn't say anything about xerces exceptions in the log. Also try cranking up the logging (debug) level for the container and/or context. Please let us know what you find!
    Chris
    17 years ago
    I think maybe the wording could be a little better, but I would agree with A and B if they went more like this:
    A. A static inner class has no (implicit) references to an instance of the enclosing class.
    B. Static members of a static inner class can be referenced using the (fully resolved) class name of the static inner class.
    I might even try to add something to B about how the members must be visible (ie not private, etc).
    HTH,
    Chris
    We know the compiler allows this

    Without that, you wouldn't be able to assign an integer constant (24) value to a type smaller than int without casting. Since the value of 24 is known at compile time, the compiler can check it for overflow (try using 240 instead of 24, the compiler will complain).
    Since a final variable is, well, final , the statement above is saying this will work also (and it does).

    HTH,
    Chris
    This is just a shot in the dark, but have you tried redirecting the client using response.sendRedirect()? I don't know why the container isn't invalidating the session, but this would force a new request from the client, and may solve the problem (in a way that shouldn't be container specific).
    Chris
    17 years ago
    I have also had success with creating a class that implements HttpServletResponse to wrap the true HttpServletResponse object provided by the container. Most of the calls are passed through (sendRedirect, addHeader, etc) but overriding the getWriter() method (and all the associated methods - flush, close, etc) to work on my own PrintWriter. To obtain the output, create an instance of the Adapter and pass it to RequestDispatcher.include(request, wrappedResponse).
    I believe you could also do something similar with the 2.3 Filtering API, if you have that available in your container.
    I have the code, if you'd like it. I think it's too long to post here.
    Chris
    18 years ago
    JSP
    JavaOne.
    As much as they whine at the conference about "we don't make any money off this.."
    Some vendors/developers get in free, but some pay more, so just an approximation:
    Average conference fee: $1800 ($2000 at door, $1600 early bird alum fee)
    Approx number of developers @ JavaOne: 25,000
    Cheapest vendor space: $5000
    Number of vendors: ~500
    =~ $47,500,000
    I know the whole affair of putting J1 on isn't cheap, but that's a serious chunk of change, and it's hard to believe there isn't profit in that.
    Also, as said in previous posts, education, book sales, certification, J2EE vendor licensing, selling little stuffed Duke dolls, etc.
    Chris
    18 years ago
    This is a shot in the dark, but have you tried to set the content-length header to the number of bytes in your output? For a simple test, you could manually count, but for more complex output, write to a ByteArrayOutputStream. Just a guess...
    Chris
    18 years ago
    You may also find some tag libraries provide the functionality you're looking for. Check out the Jakarta Standard taglibs project, specifically the IO taglibor the Scrape taglib
    Both encapsulate a call to another URL outside the web application quite nicely.
    HTH,
    Chris
    18 years ago