Tomcat 5.0 WEB.XML

3 respostas
J

Alguém pode me dizer como deve ser a estrutura do arquivo WEB.XML do Tomcat 5.0, pois o meu não funciona:

{?xml version="1.0" encoding="ISO-8859-1"?}

{web-app xmlns="http://java.sun.com/xml/ns/j2ee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
    version="2.4"}

	{display-name} Meus exemplos {/display-name}
	{description}
		Exemplos de servlets e páginas JSP
	{/description}
	{welcome-file-list}
		{welcome-file} index.jsp {/welcome-file}
		{welcome-file} index.html{/welcome-file}
	{/welcome-file-list}
    {servlet-mapping}
        {servlet-name}invoker{/servlet-name}
        {url-pattern}/servlet/*{/url-pattern}
    {/servlet-mapping}
{/web-app}

ps: troquei os <> por {} … porque não consegui postar tags…
Obrigado };

3 Respostas

M

suas declarações e mapeamentos de servlet devem vir antes do welcome-file-list

B

Rapa…

como que vc ta definindo um mapeamento de servlet (servlet-mapping) sem definir o servlet?

da uma olhada no exemplo aqui:

&#123;web-app&#125;
	&#123;display-name&#125;blablabla...&#123;/display-name&#125;
	&#123;description&#125;exemplo de web.xml&#123;/description&#125;

	&#123;servlet&#125;
        	&#123;servlet-name&#125;com.iter.mecanismo.model&#123;/servlet-name&#125;
        	&#123;servlet-class&#125;com.iter.mecanismo.model&#123;/servlet-class&#125;
	&#123;/servlet&#125;
	&#123;servlet-mapping&#125;
        	&#123;servlet-name&#125;com.iter.mecanismo.model&#123;/servlet-name&#125;
        	&#123;url-pattern&#125;/mecanismo/*&#123;/url-pattern&#125;
	&#123;/servlet-mapping&#125;
&#123;/web-app&#125;

public static String assign() { return new String(“brupinto - ESJUG”); }

G

Exemplo completo com todas as configurações do web.xml:

&lt;?xml version=&quot;1.0&quot; encoding=&quot;ISO-8859-1&quot;?&gt;
&lt;!DOCTYPE web-app PUBLIC
    &quot;-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN&quot;
    &quot;http&#58;//java.sun.com/dtd/web-app_2_3.dtd&quot;&gt;

&lt;web-app&gt;
  &lt;!-- Order matters in web.xml! For the elements
     used in this example, this order is required&#58;
     context-param
     listener
     servlet
     servlet-mapping
     session-config
     welcome-file-list
     taglib
     security-constraint
     login-config
  --&gt;

  &lt;!-- Since the company name changes so frequently,
     supply it as a servlet context parameter instead
     of embedding it into lots of different servlets and
     JSP pages. The InitialCompanyNameListener will
     read this value and store it in the servlet context. --&gt;
  &lt;context-param&gt;
   &lt;param-name&gt;companyName&lt;/param-name&gt;
   &lt;param-value&gt;not-dot-com.com&lt;/param-value&gt;
  &lt;/context-param&gt;

  &lt;!-- Also store the previous company name. --&gt;
  &lt;context-param&gt;
   &lt;param-name&gt;formerCompanyName&lt;/param-name&gt;
   &lt;param-value&gt;hot-dot-com.com&lt;/param-value&gt;
  &lt;/context-param&gt;

  &lt;!-- Declare the names of the session attributes that
     are used to store items that customers are
     purchasing. The daily special listener will
     track changes to the values of these attributes. --&gt;
  &lt;context-param&gt;
   &lt;param-name&gt;order-attribute-names&lt;/param-name&gt;
   &lt;param-value&gt;
     orderedItem
     purchasedItem
   &lt;/param-value&gt;
  &lt;/context-param&gt;

  &lt;!-- The item names of the current daily specials. --&gt;
  &lt;context-param&gt;
   &lt;param-name&gt;daily-special-item-names&lt;/param-name&gt;
   &lt;param-value&gt;
     chalet
     car
   &lt;/param-value&gt;
  &lt;/context-param&gt;

  &lt;!-- Register the listener that sets up the
     initial company name. --&gt;
&lt;!-- Listener declaration moved to tag library...
  &lt;listener&gt;
   &lt;listener-class&gt;
     moreservlets.listeners.InitialCompanyNameListener
   &lt;/listener-class&gt;
  &lt;/listener&gt;
--&gt;
  &lt;!-- Register the listener that monitors changes to
     the company name.
  --&gt;
&lt;!-- Listener declaration moved to tag library...
  &lt;listener&gt;
   &lt;listener-class&gt;
     moreservlets.listeners.ChangedCompanyNameListener
   &lt;/listener-class&gt;
  &lt;/listener&gt;
--&gt;

  &lt;!-- Register the session counting event listener. --&gt;
  &lt;listener&gt;
   &lt;listener-class&gt;
     moreservlets.listeners.SessionCounter
   &lt;/listener-class&gt;
  &lt;/listener&gt;

  &lt;!-- Register the yacht-watching event listener. --&gt;
  &lt;listener&gt;
   &lt;listener-class&gt;
     moreservlets.listeners.YachtWatcher
   &lt;/listener-class&gt;
  &lt;/listener&gt;

  &lt;!-- Register the listener that sets up the entries
     that will be used to monitor orders for the daily
     special. --&gt;
  &lt;listener&gt;
   &lt;listener-class&gt;
     moreservlets.listeners.DailySpecialRegistrar
   &lt;/listener-class&gt;
  &lt;/listener&gt;

  &lt;!-- Register the listener that counts orders for the daily
     special. --&gt;
  &lt;listener&gt;
   &lt;listener-class&gt;
     moreservlets.listeners.DailySpecialWatcher
   &lt;/listener-class&gt;
  &lt;/listener&gt;

  &lt;!-- Register the listener that resets the order counts
     when the names of the daily specials change. --&gt;
  &lt;listener&gt;
   &lt;listener-class&gt;
     moreservlets.listeners.ChangedDailySpecialListener
   &lt;/listener-class&gt;
  &lt;/listener&gt;

  &lt;!-- Assign the name ChangeCompanyName to
     moreservlets.ChangeCompanyName. --&gt;
  &lt;servlet&gt;
   &lt;servlet-name&gt;ChangeCompanyName&lt;/servlet-name&gt;
   &lt;servlet-class&gt;moreservlets.ChangeCompanyName&lt;/servlet-class&gt;
  &lt;/servlet&gt;

  &lt;!-- Assign the name OrderHandlingServlet to
     moreservlets.OrderHandlingServlet. --&gt;
  &lt;servlet&gt;
   &lt;servlet-name&gt;OrderHandlingServlet&lt;/servlet-name&gt;
   &lt;servlet-class&gt;
     moreservlets.OrderHandlingServlet
   &lt;/servlet-class&gt;
 &lt;/servlet&gt;

  &lt;!-- Assign the name ChangeDailySpecial to
     moreservlets.ChangeDailySpecial. --&gt;
  &lt;servlet&gt;
   &lt;servlet-name&gt;ChangeDailySpecial&lt;/servlet-name&gt;
   &lt;servlet-class&gt;
     moreservlets.ChangeDailySpecial
   &lt;/servlet-class&gt;
  &lt;/servlet&gt;

  &lt;!-- Give a name to the servlet that redirects users
     to the home page.
  --&gt;
  &lt;servlet&gt;
   &lt;servlet-name&gt;Redirector&lt;/servlet-name&gt;
   &lt;servlet-class&gt;moreservlets.RedirectorServlet&lt;/servlet-class&gt;
  &lt;/servlet&gt;

  &lt;!-- Assign the URL /admin/ChangeCompanyName to the
     servlet that is named ChangeCompanyName.
  --&gt;
  &lt;servlet-mapping&gt;
   &lt;servlet-name&gt;ChangeCompanyName&lt;/servlet-name&gt;
   &lt;url-pattern&gt;/admin/ChangeCompanyName&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt;

  &lt;!-- Assign the URL /HandleOrders to the
     servlet that is named OrderHandlingServlet.
  --&gt;
  &lt;servlet-mapping&gt;
   &lt;servlet-name&gt;OrderHandlingServlet&lt;/servlet-name&gt;
   &lt;url-pattern&gt;/HandleOrders&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt;

  &lt;!-- Assign the URL /admin/ChangeDailySpecial to the
     servlet that is named ChangeDailySpecial.
  --&gt;
  &lt;servlet-mapping&gt;
   &lt;servlet-name&gt;ChangeDailySpecial&lt;/servlet-name&gt;
   &lt;url-pattern&gt;/admin/ChangeDailySpecial&lt;/url-pattern&gt;
 &lt;/servlet-mapping&gt;

  &lt;!-- Turn off invoker. Send requests to index.jsp. --&gt;
  &lt;servlet-mapping&gt;
   &lt;servlet-name&gt;Redirector&lt;/servlet-name&gt;
   &lt;url-pattern&gt;/servlet/*&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt;

  &lt;!-- Set the default session timeout to two minutes. --&gt;
  &lt;session-config&gt;
   &lt;session-timeout&gt;2&lt;/session-timeout&gt;
  &lt;/session-config&gt;

&lt;!-- If URL gives a directory but no filename, try index.jsp
   first and index.html second. If neither is found,
   the result is server specific &#40;e.g., a directory
   listing&#41;. Order of elements in web.xml matters.
   welcome-file-list needs to come after servlet but
   before error-page.
  --&gt;
  &lt;welcome-file-list&gt;
   &lt;welcome-file&gt;index.jsp&lt;/welcome-file&gt;
   &lt;welcome-file&gt;index.html&lt;/welcome-file&gt;
  &lt;/welcome-file-list&gt;

  &lt;!-- Register the company-name tag library. --&gt;
  &lt;taglib&gt;
   &lt;taglib-uri&gt;
     /company-name-taglib.tld
   &lt;/taglib-uri&gt;
   &lt;taglib-location&gt;
     /WEB-INF/company-name-taglib.tld
   &lt;/taglib-location&gt;
  &lt;/taglib&gt;

  &lt;!-- Protect everything within the &quot;admin&quot; directory.
     Direct client access to this directory requires
     authentication.
  --&gt;
  &lt;security-constraint&gt;
   &lt;web-resource-collection&gt;
     &lt;web-resource-name&gt;Admin&lt;/web-resource-name&gt;
     &lt;url-pattern&gt;/admin/*&lt;/url-pattern&gt;
   &lt;/web-resource-collection&gt;
   &lt;auth-constraint&gt;
     &lt;role-name&gt;ceo&lt;/role-name&gt;
   &lt;/auth-constraint&gt;
  &lt;/security-constraint&gt;

  &lt;!-- Tell the server to use form-based authentication. --&gt;
   &lt;login-config&gt;
     &lt;auth-method&gt;FORM&lt;/auth-method&gt;
     &lt;form-login-config&gt;
      &lt;form-login-page&gt;/admin/login.jsp&lt;/form-login-page&gt;
      &lt;form-error-page&gt;/admin/login-error.jsp&lt;/form-error-page&gt;
     &lt;/form-login-config&gt;
  &lt;/login-config&gt;
&lt;/web-app&gt;

:wink:

Criado 7 de julho de 2005
Ultima resposta 7 de jul. de 2005
Respostas 3
Participantes 4