• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

can't access servlet

 
Ranch Hand
Posts: 618
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...
 
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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?
 
Stephen Huey
Ranch Hand
Posts: 618
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 618
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 618
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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'm a lumberjack and I'm okay, I sleep all night and work all day. Lumberjack ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic