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

J Chandler

Ranch Hand
+ Follow
since May 17, 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 J Chandler

Hey ,

Having a little trouble running the DiceRoller code (p389).

Coded the DiceRoller class, the TLD and the JSP as instructed, but I think
the problem may lie in the DD (p390 shows web.xml right there alongside
the TLD)

If there is no servlet involved and I need to call the JSP directly, what
should the DD contain?

I have tried inserting
in the place of
because I know that the jsp gets servlet status at some point.

Am I barking up the wrong tree guys?

The error I'm getting just says the jsp can't be found.
Hope you can help.

JJ
[ October 19, 2004: Message edited by: J Chandler ]
Hi nani,

when we want to implement a Listener interface, we need to declare it
somewhere so the compiler knows.
That means either making our own listener class to handle all the methods
in the listener interface ...
OR, what would be best in this case, because ItemListener has only 1 method - itemStateChanged - we could simply state that we are implementing the ItemListener interface when declaring the class.

Example:-


and don't forget to code your own itemStateChanged method in Class2 - if the compiler knows you want to use ItemListener, it will be looking for your implementation of this method.

Example:-

hope that helps

[ October 19, 2004: Message edited by: J Chandler ]

[ October 19, 2004: Message edited by: J Chandler ]
[ October 19, 2004: Message edited by: J Chandler ]
17 years ago
Craig,

thanks for your reply...

So, I could pass a filename in through the constructor, each time I want to load a new image, right?


public class FindingImages {
public FindingImages(String filename) {
Image image = loadImage(filename);
ImageIcon icon = new ImageIcon(image);
etc.....
}

private Image loadImage(String filename) {
//won't need this now
//String fileName = "images/cougar.jpg";
BufferedImage image = null;
try {
URL url = getClass().getResource(filename);
image = ImageIO.read(url);
}
etc...
}

public static void main(String[] args) {
new FindingImages("images/couger.jpg");
}
}



Javaoops - I will also try backing up the hierarchy using your suggested method...
So, I don't have to keep my image files in any set place?
I had them in the gui package, but as long as I can navigate anywhere, I may as well put them in their own folder named images.

Thanks for all the help you guys...if I got it all wrong, please post a virtual kick in the pants and put me straight!

Cheers,
J

[ September 28, 2004: Message edited by: J Chandler ]
[ September 27, 2004: Message edited by: J Chandler ]
17 years ago
ok, I give in...

trawled all resources I have on hand - books, net, even grilled my 14 yr old son ... I just haven't turned up anything specific to what I'm trying to do.

More help would be gratefully received,
regards, JJ
17 years ago
Craig -

thanks for the advice - I didn't know I could navigate back up the file hierarchy!

Had no luck in finding the solution yet though...
tried re-arranging the path in several different ways, calling getParent()
...(which compiled but didn't work)
...also done many searches to find info about navigating back up the file hierarchy, but no joy as yet.

Will keep trying
J
17 years ago
Hey you guys,

I finished a 3 tiered standalone application that has a neat looking GUI (for a swing beginner)...

problem is, when I tested the packaged app on another system everything worked fine apart from all my images, which failed to appear.

The images are used as backgrounds for all my different screens and components are positioned on top using GridbagLayout/constraints etc...
Works fine on my system and I have placed all the relevant image files in the gui package.

I think the problem lies in the filepath specification, where I defined it as:

filename = "c:/JavaParcs/project/gui/lake.jpg";



This is specific to my system but how can I fix it so that it can be accessed by any other?
(I tried taking out the c:/ and the pics dissappeared on mine too)
I also tried:

filename = "./JavaParcs/project/gui/lake.jpg";


thinking that if a dot means look in the current dir.... but that didn't work either.



Can anyone help or at least point me to a relevant resource on the matter?

Regards,
J
[ September 24, 2004: Message edited by: J Chandler ]
17 years ago
Hey Bert,

tried what you suggested and still got the error...

I deleted the jsp file and started over... now everything's ok!

Thanks for your time

Onward and upward!
J
Hey,

I keep getting a 404 error - (The requested resource (/result.jsp) is not available) - when I run version 3 of the BeerSelect.java servlet...

via localhost:8080/Beer-v1/form.html in the browser

I think my servlet code is ok, as there is obviously an attempt being made to find result.jsp in order to send the request and response objects to it.

result.jsp is situated in:
MyProjects/beerV1/web/result.jsp
and
tomcat/web-apps/Beer-v1/WEB-INF/result.jsp

Any ideas?

regards, J


[ September 23, 2004: Message edited by: J Chandler ]
[ September 23, 2004: Message edited by: J Chandler ]
ok, I've been wandering about trying to find a solution to my problem and for anyone who is having the same trouble...

check out the post from September 14th (command line arguments)

I would like to thank Jaques CestJaques for hitting the nail on the head.

If you are using Windows XP, you need to substitute the colons with semi-colons.

javac -classpath C:/tomcat/common/lib/servlet-api.jar;classes;. -d classes src/com/example/web/BeerSelect.java



Happy days
Thanks for the response

First, Pallavi, I don't have a J2ee.jar file so I think that would not work for me at this point - but thanks anyway mate!

Kathy, I have checked that I'm compiling from the development environment -

I have to type:

cd C:\MyProjects\beerV1



I back-tracked to page 81 and commented out some code from BeerSelect.java so that I had the first version again.

To compile I type:

javac -classpath C:/tomcat/common/lib/servlet-api.jar:classes:. -d classes src/com/example/web/BeerSelect.java



This generates 6 'can't see any servlet related api' type errors.
But, if I compile without :classes:., it works fine.
(I'm guessing that I really NEED to make it compile with :classes:. for the reasons you explained in your post)

Moving on, my BeerExpert.java file DOES compile correctly with :classes:.

This brings me back to version 2 of (naughty)BeerSelect.java, which once again throws up the same 6 'can't see any servlet related api' type errors - PLUS another 3 'ha ha, can't see com.example.model either, so ner' type errors.

All package statements and import statements are present and correct.
I'm stumped

Regards, J
[ September 22, 2004: Message edited by: J Chandler ]
Hey everyone

Reached page 85 without too many hitches but I'm having a tough time re-compiling the BeerSelect servlet class.

Compiler does not recognize package com.example.model (says it doesn't exist.

I feel it may be a classpath problem as I've checked the hierarchy of all the files many times and each package statement therein (hmmmmm).

BTW, I notice that the command line screen dump (p85) has an additional bit after servlet-api.jar

:classes:.


that wasn't used for the first example (p31, step 5).
This does not work for me as it it hides all servlet related code from my compiler and it gets upset and shouts - (I use Windows)

Any advice would be appreciated

Cheers, J
Hey guys,

I ordered a copy of HF Servlets & JSP on 28th June from Amazon(UK)...

it arrived 2 days ago (September 18th) when I had all but given up on it!

Well worth the wait though.

J
[ September 20, 2004: Message edited by: J Chandler ]
Jules,



found it!!!

here's where I was going wrong - in my bookCabin(id, dateRequested, guest) method, I was using ListIterator to look through and compare available dates with the date that the user/guest had requested.

I used i.next() for the comparison - if I got a match, I used i.previous() to obtain the value and assign it to a variable, then continue with the booking process.

Main problem was the same value was being compared again and again because the 'pointer' was jumping back and forth over the date we needed to book, booking it over and over. :roll:

Solutions:
assign i.next() to a variable first before the comparison - therefore no need to use i.previous() (but then I may as well have used plain old Iterator instead of ListIterator.

OR

return from the method as soon as the date has been booked instead of letting it iterate through the rest - less cost if the list is long and better programming practice.

I have filed this example under 'Stupid mistakes #527' (chortle)

Jules, thanks for all your help, mate,
Regards,
J
Woe is me...

it appears I have failed to resolve the above problem

It's not the GUI implementation - command line reacts the same if I modify data right there, on DosPrompt.

I think something mad happens when the persist() method calls a getId()method to form the filepath statement.
This is exactly where the logging info statement prints out over and over.

...and still the file is saved successfully, but in a very messy way.

J has a headache - please make comments you guys - I'll try any ideas