wood burning stoves 2.0*
The moose likes Servlets and the fly likes can't access servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "can Watch "can New topic
Author

can't access servlet

Stephen Huey
Ranch Hand

Joined: Jul 15, 2003
Posts: 618
I'm working on a project in JBuilder that has been around for about a year, and one of my frustrations with the site is that it's a bit too JSP-centric for my liking, so I'm trying to experiment by adding some servlets. However, I don't know how to have my form POST to my servlet.
If my servlet is called Controller, then the action on the form should just be Controller, right?
Let's say my main package where all the JSPs are and the corresponding directory under Tomcat's webapps folder is called general. Then in JBuilder, some of the JavaBeans and other Java classes are in packages under general, like general.beans and general.utility, so in a JSP on the site, I access those Java classes by specifying their package names, like this:

JBuilder compiles all these beans and other classes into a JAR file that I stick in Tomcat's common\lib folder, and the JSPs go into that folder under the webapps folder (I didn't set this up). So, I assume my servlets are in that JAR file, and should be accessible somehow. I tried to make my Controller servlet be in the same "package" as the JSPs--in that general one, but I guess that doesn't really make sense. When I tried to put them all in the same package or directory in the JBuilder Project browser, it put them under an Additional Settings section instead of placing them next to the JSPs.
Any ideas as to how I can get this to work with the current configuration? I don't know tons about JBuilder, so I'm not sure I'd want to modify how all this stuff is working right now.
Thanks...
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60794
    
  65

If my servlet is called Controller, then the action on the form should just be Controller, right?

Have you mapped the servlet to the name "Controller" in the web.xml?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Stephen Huey
Ranch Hand

Joined: Jul 15, 2003
Posts: 618
I have a servlet called LookupServlet, and in my web.xml I have this:

In my JSP, I'm trying to POST to that servlet with this line:

However, when I try to POST from the page, it just looks for Lookup in that directory (and doesn't find it--I get an HTTP 404 code).
All I know is that all pure Java files (non-JSP) I have in JBuilder get lumped into a big JAR file that I stick in Tomcat's common\lib directory, and it always manages to find them that way. I assume my servlet code is being put in there as well, but I don't know how to find it (how do I tell it when the form is submitted to not look in that directory, but instead go look at the mappings in web.xml?).
Thanks...
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60794
    
  65

Try:

This will prefix the servlet reference with whatever context path ("web app name") is appropriate (which will be "" for the root context).
[ February 17, 2004: Message edited by: Bear Bibeault ]
Stephen Huey
Ranch Hand

Joined: Jul 15, 2003
Posts: 618
Thanks for trying to help, but this doesn't seem to be working.
I don't know what JBuilder is doing--whether or not it's putting my servlet Java files in that big generated JAR file that I stick in Tomcat's common\lib or not. I've been poking around, and found the original servlet Java file in one of the numerous source directories, and I also found the servlet class file. I tried sticking both of those in my "general" directory where all the JSPs reside in Tomcat, and the reason I put them there is because my servlet is in the "general" package.
However, when I do the form post with that getContextPath(), it looks for general/Lookup, which seems to say that the "general" directory is the context path. However, I don't think that's where my servlets are in Tomcat--I mean, if they are in that big JAR file, I don't think that I can pretend their class files are in that directory.
I don't think I'm making sense here. I'm not sure how to explain this. Maybe I should figure out another way to go about this!
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60794
    
  65

it looks for general/Lookup,

I think we are on the right track. It should be /general/Lookup. Please check my post, I made a change to it that may have been made after you saw it.
Btw, in this case 'general' does not represent a physical folder, but a virtual path to your web app. I am assuming that you have deployed your app as the context "general"?
[ February 17, 2004: Message edited by: Bear Bibeault ]
Stephen Huey
Ranch Hand

Joined: Jul 15, 2003
Posts: 618
Thanks for all the help. I have a simple test servlet that I'm trying to do this with and I think I'm a bit closer. I didn't have the servlet-mapping in my web.xml. Before I just had this:

Now I have all this:

I forgot I had said my Controller servlet was in the "general" package (thanks to the automatic stuff in JBuilder making things a bit too fast for me!). However, when I stuck the servlet class file in the general directory where my JSPs were (under webapps), it didn't pick it up. I experimented and figured out that it found my servlet if I made a directory called "general" in my Tomcat's common\classes directory and stuck the Controller class file in there.
From here, I can send redirects to other JSPs and all that jazz, which is kind of amazing to me...I guess I should familiarize myself with web.xml and server.xml a bit more to be more certain of how Tomcat knows where everything is.
One thing I am wondering (that I'm sure I can find out by reading up on it) is how my servlets can access all my bean info (since in the JSPs I can use the usebean tag), in case they need to pull some global info when a request comes in. But maybe I'm thinking about servlets inappropriately...would I just have one instance of a servlet for all users, or is it an instance for every session like my beans? It's gotta be the latter, right...?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: can't access servlet
 
Similar Threads
Tomcat6 and Java Beans
help with session listener
servlets and new web directory
Servlet package and Tomcat Question
Starting new project Tomcat