Okay, so I know this is in the first chapter of whatever JavaRanch recommended book I read on JSP long ago, but I haven't written any JSP (or Java for that matter) in a long time, so I can't remember how to do this.
So far this is what I have done:
Made a DB
Wrote an HTML page to send data to a JSP
Got those values in the JSP
Queried the database with those values
This all works great, but the code is really ugly. Now I want to put that database access code into a class file. That way it's not clogging up my JSP. I have a vague recollection of how to do this, but can't remember exactly. I think what you are supposed to do is something like this.
Make a java file
Compile it (?)
Put the .class into a jar (or the .java?)
Put the .jar into a directory (WEB-INF? WEB_INF/classes?)
Import the .jar
Is that right? Exactly how is this done? Where is the jar supposed to go? Is there an example of this somewhere I can try to get working minimally before I start messing with my already written code? It would be nice to see a tutorial that gives you an itty-bitty JSP that imports a class that just returns a string so that the JSP can print it, and shows you how to jar everything up and where to put each piece of the code.
Can someone explain this or point me at a good reference? Everything I have seen so far just confuses me more.
I know how to write a servlet and how to write a JSP but I keep hearing people talk about these other technologies. I read about them somewhat on the wikipedia but I don't have a very good idea how the terms relate to each other. JSPs and Servlets are pretty basic units. I gather that these other technologies are more like ways of using them. Even more different, web services seem like they are a concept, not really a specific technology.
Somebody help me out with the big picture here. How do these technologies relate to each other? How are they the same or different? What is one good example of an application that would lend itself well to being written in each? Is there anything else I should've included in the list to get a full understanding?
Anything anyone wants to throw out there will be very helpful. Thanks. [ September 18, 2006: Message edited by: Rebecca Witmer ]
I have an application that is WARred up in the typical J2EE fashion. There are a bunch of 3rd party JAR files that need to be included in its lib folder. I put them in there and deployed the WAR, but when weblogic starts up it gives all these errors about not being able to find certain classes from the JARs. As an alternative, I tried putting the paths to those JARs in the CLASSPATH system variable and it worked.
Why doesn't weblogic find my JAR files if they are inside \WEB-INF\lib? Is it something to do with the order things are loaded by the classloader? Could it be that it's trying to load my classes first and the library JARs second when I put those JARs in the lib? Would it load the JARs first when I put them in the CLASSPATH instead?
After five days of banging my head on this problem I have found somewhat of an answer. For some reason swing only wants to refresh the scrollbar if an event occurs. When someone clicked in my tree and event occurred and it was happy about running the setValue command to scroll the bar to the top. However, my ultimate goal was to change the text each time someone clicked in the tree, which would set the scroll bar back to the bottom. So I needed another type of event to occur that would not involve the user clicking. After all, what I am trying to avoid in the first place is making the user drag the scrollbar back to the top. So it occurred to me to do the following...
...and add a method like this.
If I ever want to put the scroll bar at the top I just call timer.start();. The setValue() method will run inside the event even though it won't other places. I hope that helps someone in the future. Does anybody with any better knowledge of the way this all work have an explanation as to why it behaves this way? Is it a bug in Swing?
Okay, so I have been pondering this some more and I've come up with a lot of confusing data. Is there another way to do this scrollpane stuff? I am baffled. Maybe someone else won't be. Here's what I've come up with:
There are two scroll panes side-by-side in my gui. The left one has a tree of stuff you can click on to see metadata about it in the left side. Here's some code I have for setting up the panes (partially):
So that's at the beginning. When it first sets up the panels it always tells me: Value of scrollbar is 0 Value of scrollbar is 0 That's right because the default is for there to be no vertical scrollbar unless the text stretches it out. Since there's no text yet, no scrollbar. Thus its value is 0.
Then I have added this to the code that runs when you click something on the left. I tried all _kinds_ of stuff to get it to behave:
But nothing works. The scroll bar stays not at the very bottom, but one or two pixels away, exactly at the bottom of the final character. Here's some output:
Value of scrollbar is 0 <---Initial values Value of scrollbar is 0
Value of scrollbar before value changed is 0 <---After I clicked something Value of scrollbar after value changed once is 0 Maximum is 295 Minimum is 0 Value of scrollbar after value changed twice is 0
Value of scrollbar before value changed is 252 <---The 2nd thing clicked Value of scrollbar after value changed once is 0 Maximum is 295 Minimum is 0 Value of scrollbar after value changed twice is 0
Value of scrollbar before value changed is 86 <---Dragged the s.b. to the Value of scrollbar after value changed once is 0 <---middle then clicked Maximum is 295 Minimum is 0 Value of scrollbar after value changed twice is 0
If you take out setting the size of the JEditorPane to 295 and just let it figure out its own size it will say that the value of the scrollbar is 25 or 40 depending whether you add on another "Y" or not. That is, it sets the size and scroll bar value to match the amount of text.
I don't get why it wants to be at the bottom but at this point I am so baffled that I am willing to trash this idea and try another way. Is there another elegant way to do this?