• Post Reply Bookmark Topic Watch Topic
  • New Topic

Invoking servlets from JSP's  RSS feed

 
Tony O'Neill
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Everyone

I hope I am putting this query in the correct discussion group, but if I have not, then please accept my apologies in

advance.

I have created a web application using JSP's, Tags, Beans and Servlets running correctly and reliably in the Tomcat

Server.

I decided to migrate this application to run in the JBoss Server.
However I find that I am having trouble invoking the servlets from the Java Server Pages.
Interestingly though, the JSP's have no problem accessing the custom tags.


Typically the servlets are invoked with this kind of code:

<FORM ACTION= <%= "servlet/ValidateUserServlet" %> METHOD="POST" NAME="loginForm" >


But the server tells me that the servlet in question cannot be accessed.

The directory structure is standard:

WEB-INF/classes/myapp/servlets

The strange thing is that the tags have the same directory structure:

WEB-INF/classes/myapp/tags


The ANT build file for this application compiles and produces both a correctly structured Web ARchive file and a correctly

structured Enterprise ARchive file.

The WEB-INF directory looks like this:

WEB-INF/web.xml

WEB-INF/application.xml ( this file specifies the root for the Web ARchive file )

WEB-INF/classes...

WEB-INF/MyTagLibrary/taglib.tld


I have been 'hacking' away at this for a week now with no success. I would be very gratefull to anyone with any suggestions as to how to fix this.
 
sudhir kamath
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi tony,

If it working really fine with tomcat then it problem with directory structure of your web application. You have to look into your war file that is deployed on jboss.

HTH
Regards,
Sundeep.
 
Indraneel A Das
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hope i'm understanding your problem correctly

<FORM ACTION= <%= "servlet/ValidateUserServlet" %> METHOD="POST" NAME="loginForm" >

is equivalent to

<FORM ACTION="servlet/ValidateUserServlet" METHOD="POST" NAME="loginForm" >

the ValidateUserServlet servlet will be called when the form is submitted.

if there is no servlet mapping defined in web.xml and the servlet is not defined in any package, the web application can still locate the servlet provided the class file is present in WEB-INF/classes/ directory (i.e WEB-INF/classes/ValidateUserServlet.class)

Now, if ValidateUserServlet is defined in myapp.servlets package and class file is put as WEB-INF/classes/myapp/servlets/ValidateUserServlet.class , then you need to provide following servlet Mappings in the web.xml

<servlet>
<servlet-name>ValidateUserServlet</servlet-name>
<servlet-class>myapp.servlet.ValidateUserServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ValidateUserServlet</servlet-name>
<url-pattern>/servlet/ValidateUserServlet</url-pattern>
</servlet-mapping>
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Indraneel A Das:

if there is no servlet mapping defined in web.xml and the servlet is not defined in any package, the web application can still locate the servlet provided the class file is present in WEB-INF/classes/ directory (i.e WEB-INF/classes/ValidateUserServlet.class)


The container will only be able to locate the servlet if it is mapped or if the invoker servlet is active. If you weren't mapping your servlets and they were working with Tomcat, then it was using the invoker servlet.

If you were calling your servlets that way and you are migrating your app, now is a good time tighten things up by creating the mappings.
 
Tony O'Neill
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello again,

I just want to say a big Thank-You to Sundeep, Indraneel and Ben for your swift and helpfull responces to my query. I will apply your suggestions to my application. Though we will never meet, it is nice to know that there are generous people out there in Java-Land.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!