Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!

Hartmut Ludwig

Ranch Hand
+ Follow
since Aug 31, 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 Hartmut Ludwig

Originally posted by Andrew Parker:

Moreover, how should I click sort by id, name or salary and go to the proper try block?


First of all you should be able to use the same Method for all three sorting tasks.
So you need to write a sorting-Method that takes the field you want to sort as a String parameter.
This parameter will be taken from the URL-Request (by adding it to the URL that calls the servlet).
The link would point to something like:
http://www.example.com/myServlet?sorting=salary
You can now get the parameter "sorting" within the servlet and use it within the SQL-Statement. You have chosen to use a prepared statemet. This is generally a good choice, but you did not use it as intended.
Try to find out more about prepared statements. They offer the ability to enter question marks which are replaced by the user input.
You can use a question mark in the "order by" clause of your statement and replace it with the given order parameter.
One more suggestion:
It makes no sense to put a finally-block within a try-block. Finally is done in the end of processing after try and cach have been done.
So first handle catch-blocks and than add a finally block in the very end.
You could also close the statements in try and catch directly and don't need any finally at all.
good luck
Hartmut
19 years ago
JSP
Well - this is a lookup problem. Your system does not know the name "localhost".
You can easily fix this using a host file. A host file is something like a DNS-Lookup table. It assigns IPs to hostnames. The format is quite easy. My hosts-file looks like this:

You see: it contains only one entry which assigns the logical hostname "localhost" to your local loopback IP (the lines with # are treated as comments).
If you use Win9x you will find your hosts file in the system folder. If you use NT/2000/XP you will find it in system32\drivers\etc.
Edit the file and add the entry like shown above. After that everything will be fine...
cheers
Hartmut
19 years ago
JSP
You will finde some helpful examples on the usage of java beans within JSPs here
19 years ago
since we migrated our WebApp from WSAD 3.02 to 4.0 we have problems with special german characters (���).
In any JSP or file generated by Servlets the encoding is wrong resulting in garbage characters (question-marks) where the special characters are supposed to be. I can handle this in the JSPs, by using the according HTML-Entities. However - we did not encounter this problem with WebSphere 3.02 so it should be generally possible to set the system property "default.client.encoding" to 8859_1, or something like that.
Where can I do this?
TNX for your support
19 years ago
great that it works for you.

Originally posted by kwwong wong:
However in the valueUnbound method, I need to scan all the tables with the sessionID to unlocks all locks of the according session.


Hmm. More than one table at the time. Well - this can really cause a lot of unnecessary requests to the Database.

I have another ideal to implement the locking mechanism. Can I store the locking information in ServletContext instead of tables column ?


Why not - brilliant idea. I see only three tiny drawbacks:
1. You have no real persistance in the locks (e.g. if the server fails, gets rebooted or something)
2. You won't be able to use the locks to block other applications accessing the database without using your webapp.
3. You have to deal with some probs that might occur due to synchronous access. You have to impelment a synchronized solution. We did not need to do that with the database, cause the JDBC-Driver and the Database itself did it for us.
But all this is not a big problem - so your approach is better since it is much quicker and causes less load for the CPU.

But I don't know how to implement the collection. Using Collection , Vector, List or implement by myself ?


Oh that's the easy part! You could use any of the mentioned approaches. Maybe for our needs the synchronizedMap() from the collections API (java.util.Collections
in Java 1.4) would fit best. It allows to search the collection by a specified key and avoids duplicate keys (which won't occur in our program anyway).
The key for the collection would consist of the combination of databasekey and tablename.
So... create an Object LockMap which extends java.util.AbstractMap and add the features you
mentioned. Create an Instance of it in the init() Method of the servlet as synchronizedMap...
Map myLocks = Collections.synchronizedMap(new LockMap());
Add it to the servlets Context. Now you can do the locking with this object instead of the database. The code itself could look somewhat like this:

ATTENTION: I haven't tested this at all (just to keep some work left for you)
But I honestly think it goes into the right direction and I hope it helps.
BTW: I never worked with the Collection API before, but it seems like it's quite useful.
good luck
Hartmut
19 years ago
JSP
Hi, Pravin,

Do I need to enable file handling in some jsp tag? [...]
Should I add sothing more in page tad or any other tag?


Nope. You just made a mistake in your code.
Read carefully over the line:
FileReader writer = new FileReader("\\\\myServer\\jsp_test\\doc\\data\\BuildingInfo.txt");
Do you see it? You try to define a previously defined variable (writer). This won't work.
Use the old code you posted here and add the code I wrote just in front of it.
sl
Hartmut
19 years ago
JSP
Hi, Kam Wah!
Yes, indeed, you need to pass the name of the table you refer to in the following methods of the SessionLockManager.
isDoubleEdit(key, id)
isRecordLocked(key, id)
lockRecord(key, id)
unlockRecord(id)
I recommend that you overload them to:
isDoubleEdit(tableName, key, id)
isRecordLocked(tableName, key, id)
lockRecord(tableName, key, id)
unlockRecord(tableName, id)
and use the variable tableName in the SELECT- and UPDATE-Statements instead of the hardcoded "test" I used so far.
good luck and let me know if it works.
cheers
Hartmut
19 years ago
JSP
We need more information to help you.
In which directory did you place your JSP?
What are the corresponding settings in your server.xml?
The more information you give about your problem the more precise the ansers will be.
Hartmut
19 years ago
JSP
Well - the exception says quite clearly what happens: "No such file or directory".
I guess you placed a BuildingInfo.txt somewhere, but not where it is expected.
Since you did not tell us - let me guess: You placed it in the webapps home directory.
But the JSP seems to search somewhere else. Hmm how can we find out where the JSP is looking for it?
Just let's simply turn it the other way round and let the JSP write some code. Then we will see which directory is used.
So add a few lines in front of your existing code:
<%try {
FileWriter writer = new FileWriter("BuildingInfo.txt");
writer.write("here it is");
writer.close();
}
catch(Exception e){
out.print("Exception :"+e.toString());
}%>
You can add this in front of your existing code and you will see a "working good" in your browser window.
Why is this? Because the file has been written to the place where the JSP expects it. So your other code now can find it (of course not the one you wanted to read, but the one containing the "here it is" which has been created before).
Now you can use the find command of your OS to locate it.
Let's assume you use Windows you will find it in C:\
This is not very surprising, because you did not name any directory so the VM uses the root directory of your OS.
You need to give the full path if you want to read/write from a particular place in the filesystem.
sl
Hartmut
19 years ago
JSP
You can use the Application Events Framework to achieve this.
Here's the explanation. (look for SessionCounter.java and session-counts.jsp).
This works only for Servlet 2.2 spec.
sl
Hartmut
19 years ago
JSP
I guess your problem is that you did not put the binary jarfile of your MM MySQL Driver to the classpath. You used the the source-jar instead. The binary must be named something like:
mm.mysql-2.0.14-bin.jar.
If you only have this source jarfile you could compile it and add the resulting jar to your classpath.
You can also download the latest Driver-package from here.
The zipfile contains the binary jar called:
mysql-connector-java-2.0.14-bin.jar.
sl
Hartmut
Try the following:
Put Username and Password and the URL itself in separate Strings.

Now you can use the following:

I'm quite shure that this will work.
Thanks a lot, Kyle, for your quick reply which was very helpful for me. I did not test it so far, but I guess I got it now.
BTW I did not want to share the utility-classes between different EARs, but between different components of one EAR. And since we permanently develop the utility classes as well as the EAR components, the article of Tim deBoer seems to provide a good solution for us.
Thanx again. Great to have you here on the ranch...
Hartmut
19 years ago
Hi, Kyle,
I have a related question. I am new to WSAD and wonder how it would be possible to incorporate the externally linked jarfiles from this lib-tab into the actual EAR-File.
Everytime I construct the ear it only contains the code I have written, but not the necessary files from the external jars. If i deploy it it won't work - only if I put the linked jars into the classpath of the webapp. But this is not the propper solution, is it?
In more general terms: We have some base classes which will be used by the ejb as well as the client application or some servlets (in the webapp). I would like to export those files only once as a separate jar instead of incorporating it into the ejb and the clientapp.
Can you tell me how this is done?
TNX in advance...
Hartmut
19 years ago