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?
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?
Of course you can do that:
Create Servlet classes / JSP files. Package them all in a .jar file. Don't include web.xml
or any other files.
Import the jar in your web application classpath
.
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>