Win a copy of Spark in Action this week in the Open Source Projects forum!

Jaap van Hengstum

Greenhorn
+ Follow
since Jul 24, 2003
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 Jaap van Hengstum

Today we talked about some design issues for a web application we are doing. We had an discussion about something and I settled for something I disagreed with because two people (whose opinions I normally respect) thought my solution was a bad idea.

However, I feel that I finally agreed because it was 2 to 1, not because I think their solution is better. Both solutions had their pros and cons, but I still think my solution has the better advantages but I couldn't convince them of that.

How do you handle these situations? Are you going for the democratic approach or will you do everything possible to push your solution as the definitive one?
16 years ago
I don't believe this is possible withouth resorting to JNI. This library uses some JNI code to find out the MAC address of the network card on various platforms; maybe it is of some use to you.
16 years ago
You might also want to take a look at some of the html-templating languages for Java, like Velocity or Freemarker. These are especially tailored for creating html representations of java objects, the advantages over XML/XSL being simpler to use and no need to convert your java objects to XML first (a disadvantage is that they are more java-platform dependent).
You could f.e. just have a generic renderer object that takes a javabean (the model) and a template string/stream (the view) and generates the html.
16 years ago

Originally posted by Rob Levo:

Jaap,
You are the best! Struggled with this for days with no success, and your code fixed the problem.
Can you please explain what the caching problem was, so I can understand going forward.


I spent quite a few hours on a similar problem also, so I can understand
What I know is that, in my situation, when you are running your servlet from within a security-constraint or HTTPS site, the server (Tomcat in my case) will automatically send a "Cache-Control: no-cache" header with every page (for obvious security reasons). This causes the browser (IE in my case) to disable caching the pages, so when a file is downloaded it is not stored on the disk (unless you specifically request to save it to another file by choosing 'save' in the popup dialog instead of 'open') and in some cases the browser cannot even remember the filename (which might or might not be a bug in IE).
So the solution is to overwrite the Cache-Control header when using content-disposition to download or display a file by setting the header in the code. The Cache-Control header can be set to 'public' or 'private' and I think 'private' may actually be a better choice because, according to the documentation, this requests public proxies not to cache the file but only private caches like the browser cache. I tried this and it works in IE.
This is what I know about this issue.
[ March 18, 2004: Message edited by: Jaap van Hengstum ]
16 years ago
Maybe it's a caching problem. Try adding res.setHeader("Cache-Control", "public") to your servlet.
16 years ago
What I usually do, is store the files outside of the webroot and use a servlet to read the file and present it to the user if the user has the necessary rights. These rights can be stored, f.e. in a database, together with the filename and other information about the uploaded document. Because the files are stored outside of the webroot, they cannot be requested by typing in the url in the browser.
The code in the servlet that requests the file could look something like this (I simplified it a bit, but you should get the point):

It uses a content-disposition header so that most browsers will allow the user to open the file or save it to disk (you can also use content-disposition 'inline' to open the file in the browser). Make sure the fileName is formatted properly, or a creative user will be able to download any file on the system
[ March 10, 2004: Message edited by: Jaap van Hengstum ]
16 years ago
Another http api than the one mentioned on javajunkies is the Jakarta Commons HTTPClient. You might want to check that out also...
[ February 22, 2004: Message edited by: Jaap van Hengstum ]
16 years ago
Well, from the JDK 1.4.2 documentation:


/**
* This class consists exclusively of static methods that operate on or return
* collections. It contains polymorphic algorithms that operate on
* collections, "wrappers", which return a new collection backed by a
* specified collection, and a few other odds and ends.
*
* <p>The documentation for the polymorphic algorithms contained in this class
* generally includes a brief description of the <i>implementation</i>. Such
* descriptions should be regarded as <i>implementation notes</i>, rather than
* parts of the <i>specification</i>. Implementors should feel free to
* substitute other algorithms, so long as the specification itself is adhered
* to. (For example, the algorithm used by <tt>sort</tt> does not have to be
* a mergesort, but it does have to be <i>stable</i>.)


So the Sun JDK 1.4.2 uses a mergesort, but it really depends on which Java version you use to compile your code with.
16 years ago
Encapsulation in general is the process of enclosing one or more items in a container. The container, in OOP, is an object. The user accesses the information in the container through the interface of the object. The interface determines what information of the object the user can access (such as a public method) and what information is hidden for the user (such as a private method). This is data hiding. Thus, encapsulation can be a means to achieve data hiding, but not everything that is encapsulated is also hidden.
16 years ago
What are the pros/cons of using unchecked exceptions instead of SqlException in a JDBC framework, like Rod Johnson's framework or SqlExecutor?
[ November 30, 2003: Message edited by: Jaap van Hengstum ]
A programs that print out its own source code is called a Quine. Search in google for examples.
This page has a lot of examples of Java Quines. It is possible to do a Java Quine without resorting to reflection, f.e. the first program on the above webpage:
class S{public static void main(String[]a){String s="class S{public static void main(String[]a){String s=;char c=34;System.out.println(s.substring(0,52)+c+s+c+s.substring(52));}}";char c=34;System.out.println(s.substring(0,52)+c+s+c+s.substring(52));}}
Edit: sorry for the layout, but this program only works if printed on one line.
[ Edited to remove code tags. Note that the code example is one, single, long line. -ds ]
[ November 21, 2003: Message edited by: Dirk Schreckmann ]
16 years ago
Using continued fractions (I hope I've done this correctly since it was very late ):
16 years ago
You mean something like this?
16 years ago
My wrong... it seems that java is doing its own wildcard expansion (at least on Windows systems), by the way you can disable this by quoting the commandline argument, like:


myprogram "*"

16 years ago
This behaviour is because the Unix commandline has automatic wildcard expansion, which expands any given wildcard on the commandline to its matching filenames before turning control to the program.
16 years ago