> I'm moving from JServ to Tomcat.
> I have all my servlets in jar files.
> 
> I was using JSSI with JServ in order to use the <SERVLET 
> CODE=com.me.util.myServlet> Tag .
> 
> how do I do this with tomcat now?  ( let me first say that I have been 
> searching for this information for about a week.)
> 
> I can use the <jsp:include page=> tags for servlets that are not in 
> jars. but how do i use servlets in jars that are in the WEB-INF/classes dir?
> 
> is there something special in the web.xml file?
> 
> So how do i replace
> <SERVLET CODE=com.me.misc.myServlet >   /* servlet in jar file */
>     <param name="name1" value="value1">
>     <param name="name2" value="value2">
> </SERVLET>

First, the servlet has to be registered, as per Java Servlet 2.x specification in 
./WEB-INF/web.xml:

  <servlet>
    <servlet-name>MyServlet</servlet-name>
    <servlet-class>com.me.misc.myServlet</servlet-class>
  </servlet>
  <!-- now the servlet has to be mapped to handle a URL request -->
  <servlet-mapping>
    <servlet-name>MyServlet</servlet-name>
    <url-pattern>/servlet/some_path/Whatever/*</url-pattern>
  </servlet-mapping>

After this, servlet container will forard all requests of the form 
"/servlet/some_path/Whatever/..." to the servlet. Now you can use <jsp:include ...>.

> These servlets also need to be able to get the url params.

The servlet has access to the whole URL vie Servlet methods. See the specification.

> Also when I switched my old Stand alone servlets( <jsp:include page= > ) 
> to tomcat I noticed that I had to remove the out.close(); that was in 
> the servlet class file...  or tomcat would not be able to write the rest 
> of the jsp page.  This was not the behavior I observed on JServ and JRun.

Technically speaking, <jsp:include> which translates to a servlet's "include()" 
method, just "borrows" the objects ServletRequest and ServletResponse to the included 
servlet. If the included servlet closes the stream, normally, no-one after that can 
add anything. Why would you explicitely need to close the output stream? If you want 
to flush the buffer than just call "out.flush()".

Nix.


Reply via email to