0

I need to create a web application (servlets/jsp) as a JAR file which can be added in another web application in WEB-INF/lib folder. And it should be made available by making an entry in web.xml file.

Can this be done?

2
  • 2
    If you use Servlet 3.0 you can please check the following question stackoverflow.com/questions/5013917/… Commented May 9, 2013 at 8:02
  • @Karthikeyan, I use WebSphere Application Server 7 with Servlet 2.5. This post don't solve my problem.
    – Sergey
    Commented May 10, 2013 at 8:47

1 Answer 1

0

Of course you can do that:

  1. Create Servlet classes / JSP files. Package them all in a .jar file. Don't include web.xml or any other files.

  2. Import the jar in your web application classpath.

  3. Configure Servlet classes and JSP files in your web.xml as below:

For JSP:

<servlet>
    <servlet-name>MyJSPFile</servlet-name>
    <jsp-file>/path/to/jsp/MyJSP.jsp</jsp-file>
</servlet>

<servlet-mapping>
    <servlet-name>MyJSPFile</servlet-name>
    <url-pattern>/MyJSP.jsp</url-pattern>
</servlet-mapping>

For Servlet:

<servlet>
    <servlet-name>MyServlet</servlet-name>
    <servlet-class>my.servlet.classpath.MyServlet</servlet-class>
</servlet>
 
<servlet-mapping>
    <servlet-name>MyServlet</servlet-name>
    <url-pattern>/MyServlet.do</url-pattern>
</servlet-mapping>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.