Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WebSphere 8, web.xml version="3.0", default servlet-mapping?

Migrating a legacy application from WebSphere v.6 to WebSphere v.8. The application's web.xml only contains declarations of servlets but not servlet-mappings. Yet all servlets without a servlet-mapping are accessible by a default url pattern /servlet/[servlet name]. However, on WAS8, if web.xml is updated with attribute version set to "3.0":

 <web-app xmlns="http://java.sun.com/xml/ns/javaee"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
       **version="3.0"**> 

servlets loose default mapping and need to be explicitly mapped otherwise it's 404 page not found.

Is there a way in servlet 3.0 or at least WebSphere 8, to define a default url pattern for all servlets? There's InvokerServlet for tomcat, is there a version of it for WebSphere v.8?

like image 261
Maxim Suponya Avatar asked Apr 02 '12 09:04

Maxim Suponya


People also ask

How do I map a servlet in web xml?

Configuring and Mapping a Servlet This is done using the <servlet> element. Here you give the servlet a name, and writes the class name of the servlet. Second, you map the servlet to a URL or URL pattern. This is done in the <servlet-mapping> element.

Where is web xml in Websphere?

The web. xml file must reside in the WEB-INF directory under the context of the hierarchy of directories that exist for a web application.

What is the use of web xml file in servlet?

web. xml defines mappings between URL paths and the servlets that handle requests with those paths. The web server uses this configuration to identify the servlet to handle a given request and call the class method that corresponds to the request method.

How can I access servlet initialization parameters?

To retrieve initialization parameters, call the getInitParameter(String name) method from the parent javax. servlet. GenericServlet class. When passed the name of the parameter, this method returns the parameter's value as a String .


1 Answers

Turns out older versions of WebSphere used proprietary ibm-web-*.xmi descriptors to define vendor specific deployment options. However, since v8.0 the support for .xmi files got dropped (yet still supported for backwards compatibility in applications declared as servlet "2.4"). The old application I was migrating contained the following ibm-web-ext.xmi in WEB-INF:

<?xml version="1.0" encoding="UTF-8"?>
<com.ibm.ejs.models.base.extensions.webappext:WebAppExtension xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:com.ibm.ejs.models.base.extensions.webappext="webappext.xmi" xmi:id="WebApp_ID_Ext" reloadingEnabled="true" fileServingEnabled="true" directoryBrowsingEnabled="false" serveServletsByClassnameEnabled="true">
  <webApp href="WEB-INF/web.xml#cchange"/>
  <extendedServlets xmi:id="ServletExtension_1">
    <extendedServlet href="WEB-INF/web.xml#Servlet_1"/>
  </extendedServlets>
  <jspAttributes xmi:id="JSPAttribute_1" name="keepgenerated" value="true"/>
  <jspAttributes xmi:id="JSPAttribute_1333518196516" name="reloadEnabled" value="true"/>
  <jspAttributes xmi:id="JSPAttribute_1333518196517" name="reloadInterval" value="10"/>
</com.ibm.ejs.models.base.extensions.webappext:WebAppExtension>

so the attribute serveServletsByClassnameEnabled="true" made the old app map servlets by name without servlet-mapping. This is not supported if the application is servlet 3.0..

like image 118
Maxim Suponya Avatar answered Oct 17 '22 20:10

Maxim Suponya