Olá a todos,
Sou iniciante no uso de struts e servlets, e fazendo um exercício prático tive
problemas para exibir minha página web, apareceu o famoso erro 404, já procurei ajuda com outros tópicos do mesmo
assunto, mas não tive sucesso.
Segue os códigos e estruturas do meu projeto:
struts-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN"
"http://jakarta.apache.org/struts/dtds/struts-config_1_2.dtd">
<!-- -----------Faz parte do Controler-------------------------- -->
<struts-config>
<form-beans>
<form-bean dynamic="false" name="saveEditUserForm" type="strutsdemo.form.SaveEditUserForm"/>
<form-bean dynamic="true" name="saveInsertUserForm" type="org.apache.struts.validator.DynaValidatorForm">
<form-property name="idUsuario" type="java.lang.String"/>
<form-property name="login" type="java.lang.String"/>
<form-property name="nome" type="java.lang.String"/>
<form-property name="faixaIdade" type="java.lang.String"/>
<form-property name="sexo" type="java.lang.String"/>
<form-property name="ativo" type="java.lang.String"/>
<form-property name="senha" type="java.lang.String"/>
<form-property name="confirmacaoSenha" type="java.lang.String"/>
</form-bean>
</form-beans>
<action-mappings>
<action path="/listUsers" type="strutsdemo.ListUsersAction">
<forward name="sucess" path="/listUsers.jsp"/>
</action>
<action path="/editUser" scope="session" type="strutsdemo.action.EditUserAction" unknown="false" validate="false">
<forward name="sucess" path="/pages/editUser.jsp" redirect="false" contextRelative="false"/>
</action>
<action attribute="saveEditUserForm" input="/pages/editUser.jsp" name="saveEditUserForm" path="/saveEditUser" scope="session"
type="strutsdemo.action.SaveEditUserAction" unknown="false" validate="true">
<forward name="sucess" path="/pages/listUsers.jsp" redirect="false" contextRelative="false"/>
</action>
</action-mappings>
<!-- Localização do arquivo com idioma padrão -->
<message-resources parameter="resources.ApplicationResources"/>
</struts-config>
web.xml:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
"http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">
<web-app>
<!-- Standard Action Servlet Configuration (with debugging) -->
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
<init-param>
<param-name>debug</param-name>
<param-value>2</param-value>
</init-param>
<init-param>
<param-name>detail</param-name>
<param-value>2</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
<!-- Standard Action Servlet Mapping -->
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<!-- The Usual Welcome File List -->
<welcome-file-list>
<welcome-file>/pages/index.jsp</welcome-file>
</welcome-file-list>
<error-page>
<error-code>404</error-code>
<location>/pages/error.jsp</location>
</error-page>
<!-- Struts Tag Library DescriSptors -->
<taglib>
<taglib-uri>/tags/struts-bean</taglib-uri>
<taglib-location>/WEB-INF/struts-bean.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/tags/struts-html</taglib-uri>
<taglib-location>/WEB-INF/struts-html.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/tags/struts-logic</taglib-uri>
<taglib-location>/WEB-INF/struts-logic.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/tags/struts-nested</taglib-uri>
<taglib-location>/WEB-INF/struts-nested.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/tags/struts-tiles</taglib-uri>
<taglib-location>/WEB-INF/struts-tiles.tld</taglib-location>
</taglib>
</web-app>
build.xml
//Constrói a build e gera um arquivo .war para ser chamado no server
<project name="cadastro-struts" default="compile" basedir="..">
<description>
Arquivo de build de Cadastro Struts
</description>
<property environment="env"/>
<property file="build/build.properties"/>
<property name="filename" value="cadastro-struts"/>
<property name="resources" location="WEB-INF/resources"/>
<property name="src" location="src"/>
<property name="build" location="WEB-INF/classes"/>
<property name="lib" location="WEB-INF/lib"/>
<property name="servlet.jar" location="WEB-INF/lib/servlet-api.jar"/>
<property name="deploy" location="${APPLICATION_PATH}/webapps/${filename}.war"/>
<target name="init" >
<tstamp/>
<delete dir="${build}"/>
<mkdir dir="${build}"/>
</target>
<path id="project.class.path">
<pathelement path="${env.classpath}"/>
<fileset dir="${lib}">
<include name="**/*.jar"/>
</fileset>
<pathelement location="${src}"/>
<pathelement location="${build}"/>
<pathelement location="${servlet.jar}"/>
</path>
<target name="compile" depends="init" description="compila o source">
<echo message="Atenção!!! Compilando Arquivos"/>
<javac srcdir="${src}" destdir="${build}" classpathref="project.class.path"/>
<echo message="Copiando o src, xml e o property para as classes"/>
<copy todir="${build}">
<fileset dir="${src}">
<include name="**/*.properties"/>
<include name="**/*.xml"/>
</fileset>
</copy>
</target>
<target name="WAR" depends="compile, cleanContainer" description="Gerando o WAR da aplicação">
<mkdir dir="WEB-INF/lib"/>
<copy overwrite="true" todir="WEB-INF/lib">
<fileset dir="WEB-INF/lib">
<include name="**/*.jar"/>
</fileset>
</copy>
<copy overwrite="true" todir="WEB-INF/classes">
<fileset dir="WEB-INF/resources">
<include name="**/**"/>
</fileset>
</copy>
<war destfile="${filename}.war" webxml="WEB-INF/web.xml">
<fileset dir="WEB-INF">
<include name="**/**"/>
</fileset>
</war>
<move overwrite="true" file="${filename}.war" todir="${APPLICATION_PATH}/webapps"/>
</target>
<target name="cleanContainer">
<echo level="warning">Limpando diretórios</echo>
<delete failonerror="true" dir="${APPLICATION_PATH}/webapps/${appName}"/>
<delete failonerror="true" dir="${APPLICATION_PATH}/webapps/${appName}.war"/>
<delete failonerror="true" dir="${APPLICATION_PATH}/work/Catalina/localhost/${appName}"/>
</target>
</project>
Espero que possam me ajudar a resolver esse problema…
Té++
