Win a copy of Spring Boot in Practice this week in the Spring forum!

S Gibbs

Greenhorn
+ Follow
since Jul 08, 2008
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 S Gibbs

Paul Clapham wrote:

S Gibbs wrote:Hi Guys,
I'm really banging my head against a wall with this one, and was hoping someone could poke me in the right direction. I'm trying to parse xml using x:parse and the like. However I only ever get returned:


Now my understanding is that this implies that tomcat cannot see the classes involved.



No, that's wrong. It just means that the toString() method of a Document object returns that string. So it tells you that you have successfully created a Document object. As you can see it doesn't tell you anything more about that Document object; you would have to write other code to do that.



Ahh - my misunderstanding then. Thanks.
Any suggestions as to why anything else other than parse causes it to crash then?
10 years ago
JSP
Hi Guys,
I'm really banging my head against a wall with this one, and was hoping someone could poke me in the right direction. I'm trying to parse xml using x:parse and the like. However I only ever get returned:


Now my understanding is that this implies that tomcat cannot see the classes involved. However I've now put xalan.jar, resolver.jar, serializer.jar, xercesImpl.jar, xml-apis.jar, & xsltc.jar, the classes I'm told I need, in about every concivable lib folder on the server (WEB-INF/lib, the tomcat common/lib folder, and the java/lib folders) and I've had no luck.

If you try to do anything other the parse you get this error:


and for refrence this is the code I'm currently trying to just test things are working (the url is working and checked, the url var has the xml in):


Any help would be much appreciated!
Thanks
10 years ago
JSP

Originally posted by Ulf Dittmer:
Using the getClass.getResource method you can't access anything outside of the classes directory. It uses the classloader, which -no surprise there- only knows about things in the classpath.

Is there a particular reason you want to use Image.getInstance? The customary way to load images these days is javax.imageio.ImageIO.read (which can load images from everywhere, because it doesn't rely on classloaders).



That makes a lot of sense yeah >_<

The reason for the older code currently existing on the site is down to how long it's been in development. It's been a while and obviously things need updating. I'm getting it back in working order and fixing the few incomplete systems it has. The path stuff has been throwing me though! Will have a try at using the suggested method. I am concerned about resolving the file though.

Originally posted by Sravan Kumar:
1. The reason you are not able to move it out of WEB-INF/classes is because you use:

this.getClass().getResource

This obvioulsy looks for the resource in the context of the current class, which is the WEB-INF/classes folder.

2. The ideal way to read these resources (like images) in a web application is to use getServletContext().getResource() method. That way, you can place the images under your webapp context instead of WEB-INF/classes folder.

You might want to check out if there is a way of making the ServletContext object available in this class where you are loading images or if there is a way to get the image in a servlet class and making it available here.



I did have an attempt at trying to get the ServletContext object available, but it said that I was trying to use it in a non-static context or something similar. Any ideas?

Thanks for your time and help!
14 years ago
Hey everyone,
By a series of events I've ended up working on a big site made out of JSP and the like. I'm pretty happy coding java, I've done a few years at university, but obviously putting it all in a web context is a bit of a learning curve... So treat me as a newbie.

This question may seem ridiculously simple to some but I've searched all over and tried endless tests and bits of code with no joy. The site is JSP pages with some servelets and classes. Now I have some classes that are particularly useful that play with files. These originally had the path to the files hard coded in, strangely enough hardcoded paths do not work anymore after a server change (yes I did change the path to reflect the new server, still no luck ). But to be honest, why should we have hardcoded when we can have relative?

Now the classes that play with the files are not servlets are they? They're only servlets if you define them as that? (is that right?) Now after endless testing I managed to get a relative path working...


As you can probably guess though this is inside the WEB-INF/classes folder. I've tried everything to get out of the classes folder but all attempts have resulted in a null value being returned. Other methods of getting a relative path have failed (using getContext() couldn't be resolved due to not being able to extend some of the classes because they're already extended by other things :S). So feel free to give other suggestions.

Sorry if these questions are too simple, as I'm new to the language I maybe missing some vital bits of info!
Thanks for your time!
14 years ago