Menu

Creating a Web Project

James M. Payne

NOTE: These instructions use the simplest case, assuming the use of Eclipse. I am not a fan of Maven, so I will not be describing how to do this with Maven. However, if you are familiar with maven, I'm sure you can adjust as necessary.

Dynamic Web Project

  1. Right-click in the Project Explorer, and select New / Dynamic Web Project.
  2. Enter a name for the project, then click Next until you get to the last page of the wizard.
  3. Check Generate web.xml deployment descriptor and click Finish.

Even though the servlets will be using annotations, you still need the web.xml file for cluster and security settings. In addition, you may want to map library servlets (such as the Export servlet), which cannot be mapped any other way.

web.xml

Whether using in a cluster environment or not, it won't hurt to have the distributable tag. That way if you do cluster later, you don't have to worry about it. The best place for this is immediately after the display-name tag.

:::xml
  <distributable/>

If planning on using the built-in export capability in the data grids, you need to add this mapping.

:::xml
  <servlet>
    <description></description>
    <display-name>Export</display-name>
    <servlet-name>Export</servlet-name>
    <servlet-class>com.roth.servlet.ExportServlet</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>Export</servlet-name>
    <url-pattern>/Export/*</url-pattern>
  </servlet-mapping>

Security. This is important. Roth uses form authentication. This part goes at the bottom of the file before the web-app end tag. The JSP pages referenced are found in the Roth library JAR file, and are automatically referenced directly from there.

:::xml
  <error-page>
    <location>/error.jsp</location>
  </error-page>
  <login-config>
    <auth-method>FORM</auth-method>
    <form-login-config>
      <form-login-page>/login.jsp</form-login-page>
      <form-error-page>/login.jsp?error=true</form-error-page>
    </form-login-config>
  </login-config>

Full Example:

:::xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
                           xmlns="http://xmlns.jcp.org/xml/ns/javaee" 
                           xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
                           id="WebApp_ID" version="3.1">
  <display-name>ExampleWebProject</display-name>
  <distributable/>
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
  <servlet>
    <description></description>
    <display-name>Export</display-name>
    <servlet-name>Export</servlet-name>
    <servlet-class>com.roth.servlet.ExportServlet</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>Export</servlet-name>
    <url-pattern>/Export/*</url-pattern>
  </servlet-mapping>
  <error-page>
    <location>/error.jsp</location>
  </error-page>
  <login-config>
    <auth-method>FORM</auth-method>
    <form-login-config>
      <form-login-page>/login.jsp</form-login-page>
      <form-error-page>/login.jsp?error=true</form-error-page>
    </form-login-config>
  </login-config>
</web-app>

Related

Wiki: Home

MongoDB Logo MongoDB