Philip Hung

Greenhorn
+ Follow
since Dec 11, 2001
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Philip Hung

You could also replace the HashMap with a Hashtable unless you specifically want a HashMap or you are permitting null values.
That make sense. Thanks for clarifying Jeanne.
However, I'm basically using the example code in the "Core Servlet" book. There was a section regarding sending compressed pages from a servlet.
So basically what I did was replace the setContentType from ("text/html") to ("application/pdf") and push a PDF info to the output stream instead of HTML. IE was able to open the "decompressed" HTML without any dialog box coming out. But I guess it was because IE naturally understands HTML, rather than PDF which required a plug-in.
21 years ago
Hello. I'm trying to send a PDF from a servlet and was able to successfully do it, and PDF loads within the IE window. As an experiment I try to GZIP compress the PDF before I send it. The code is as follows:

The difference here is that now IE is opening a "File Download" dialog box, to save the pdf and select a viewer for the file. I was expecting that given IE is able to decompress gzip, it would first decompress the result and since I've set the content type as "application/pdf", it would open the decompressed stream in the same IE window, like the original uncompressed version of the program.
Is my assumption incorrect? or is there something that I missed in order to expect the original load behavior?
Thanks in advance.
[ July 22, 2003: Message edited by: Philip Hung ]
21 years ago
Well I found the problem already and you are right it is impossible for the DataSource to return the same connection given the underlying pool management behind it. I've taken a look at the connection wrapper class I was using and realized that it was not thread safe, making it return the same connection.
Basically the class has an instance Connection variable which is set during calls to connect().
public void connect(){
:
:
connection = myDataSource.getConnection();
:
}
and returns the connection through a getter
public Connection getConnection(){
return connection;
}
This probably will work fine in most cases, however I was using this class in a multi-threaded fashion such that if two threads simultaneously call connect(), the last connection retrieved will have overwritten the initial connection stored in the instance variable. Resulting in my using the same connection in both threads which is a violation of the latest J2EE specification.
Given two DataSource objects (DS1 and DS2) created from the same Context object and assuming both are configured to connect to the same connection pool. Is it possible that the two DataSource will return the same connection?
Connection con1 = DS1.getConnection();
Connection con2 = DS2.getConnection();
boolean test = con1 == con2;
Is it possible for the boolean variable test to be "true"? In theory, this shouldn't be possible since the connection pool should be managing which connection it gives out, so it will know what connection are "in use". Is this implementation specific? I'm using a Websphere (4.0) managed pool and it appears that I'm getting the same connection. How do I prevent this from happening?
Please help. Thanks in advance.
Here is a code snippet of my problem, I basically traverse the whole ResultSet and check each value and replace them with a corrected value if I found any violating a fix set of rules, for simplicity sake in this example I test if the value is lowercase and change it to uppercase: (I'm using an Oracle 8i database)
Connection con = DriverManager.getConnection(url,
"myLogin", "myPassword");
Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
String schema = "Schema1";
ResultSet rs = stmt.executeQuery("Select alias.* from " + schema + ".mytable alias");
ResultSetMetaData rsMeta = rs.getMetaData();
int count = rsMeta.getColumnCount();
boolean change;
while (rs.next()){
change = false;
for (int ctr = 1; ctr <= count; ++ ctr){
String temp = rs.getString(ctr);
if (!temp.equals(temp.toUpperCase())){
rs.updateString(ctr,
temp.toUpperCase());
change = true;
}
}
if (change == true) {
rs.updateRow(); // Update changes
}
}
We have two table setup one for testing and one for development, configured as different schemas but with table structures created similarly. I use the above mentioned code on the development table and it works nicely. However, when I tested it against the testing table (by changing schema variable), the application seems to hang at the rs.updateRow() call. What are the possible explanation for this and how do I resolve this?
Please help. Thanks in advance.
Thanks. Your sugggestion worked perfectly.
Hi! Can someone please tell me what I'm doing wrong?
I have an XML file and an XSL file (to convert the XML to FO). I executed the commandline version of FOP (fop.bat) as follows:
fop -xml myXML.xml -xsl myXSL.xsl -pdf myPDF.pdf
This works perfectly and the PDF was generated properly. However, when I embed the following code (example from FOP webpage) in my program I'm getting a NullPointerException:
Driver driver = new Driver();
driver.setRenderer(Driver.RENDER_PDF);
InputHandler inputHandler = new XSLTInputHandler(xmlFile, xslFile);
XMLReader parser = inputHandler.getParser();
driver.setOutputStream(new FileOutputStream(outFile));
driver.render(parser, InputHandler.getInputSource());
In addition, I used Xalan to manually convert the XML file to FO and use the other example from the FOP webpage:
Driver driver = new Driver();
driver.setRenderer(Driver.RENDER_PDF);
driver.setInputSource(new FileInputSource(args[0]));
driver.setOutputStream(new FileOutputStream(args[1]));
driver.run();
This code works perfectly and the PDF was rendered properly. According to FOP FAQ, there must be something wrong in my XSL file or XML file thus it is causing the NullPointerException. However, if this was the case then all attempts should have failed or am I missing something here? Any enlightenment would be greatly appreciated. Thanks.
The Operator Precedence would be & then ^ then |. So b2 & b3 gets evaluated first (results to true), then ^ b4 (results to false) lastly | b1 (results to true). Evaluate x++ which returns 0.
I took a mock exam once (I forgot which), but the explanation was that private methods are not overridden, I suppose they are overloaded.