} public void setTelefone(String telefone) { this.telefone = telefone; }}III) RedirectContatoAction.javaFigura 28 - Adicionando a action de redirectCODEpackage com.myapp.action;import com.myapp.service.ContatoService;import com.myapp.service.ContatoServiceImpl;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import org.apache.struts.action.Action;import org.apache.struts.action.ActionForm;import org.apache.struts.action.ActionForward;import org.apache.struts.action.ActionMapping;public class RedirectContatoAction extends Action { private ContatoService contatoService = new ContatoServiceImpl(); public void setContatoService(ContatoService contatoService) { this.contatoService = contatoService; } @Override public ActionForward execute( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {// return super.execute(mapping, form, request, response); request.setAttribute("contatos", contatoService.findAll()); return mapping.findForward("sucess"); }}7) Definindo as actions e mappings no arquivo struts-config.xmlXml<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.3//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_3.dtd"><struts-config> <form-beans> <form-bean name="contatoForm" type="com.myapp.action.ContatoForm"> </form-bean> </form-beans> <global-exceptions> <exception type="java.lang.Exception" key="user.global.ex" path="/error.jsp" /> </global-exceptions> <global-forwards> <forward name="welcome" path="/Welcome.do"/> </global-forwards> <action-mappings> <action path="/Welcome" forward="/welcomeStruts.jsp"/> <action path="/RedirectContato" type="com.myapp.action.RedirectContatoAction"> <forward name="sucess" path="/index.jsp"> </forward> </action> <action path="/CreateContato" type="com.myapp.action.CreateContatoAction" name="contatoForm" input="/RedirectContato.do"> <forward name="list" path="/RedirectContato.do"> </forward> </action> <!-- samples <action path="/" type="com.myapp." name="" scope="" validate="" input="" /> </action-mappings> --> </action-mappings> <controller processorClass="org.apache.struts.tiles.TilesRequestProcessor"/> <message-resources parameter="com/myapp/struts/ApplicationResource"/> <plug-in className="org.apache.struts.tiles.TilesPlugin" > <set-property property="definitions-config" value="/WEB-INF/tiles-defs.xml" /> <set-property property="moduleAware" value="true" /> </plug-in> <!-- ========================= Validator plugin ================================= --> <plug-in className="org.apache.struts.validator.ValidatorPlugIn"> <set-property property="pathnames" value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml"/> </plug-in> </struts-config>8) Criando a view (interface para o usuario), definindo um formFigura 29 - Arquivo index.jspCODECODE9) criar uma pagina que mostre os erros quando acontecerFigura 30 - Preparando uma pagina p/ mostrar os errosFigura 31 - Pagina error.jspo projeto deve estar assim :Figura 32 - Estrutura do projeto ate esse ponto3) Testando o Projeto WebRun>> ProjectFigura 33 - Testando a appFigura 34 - Testando a app, mais um cadastroFigura 35 - O programa em Swing da licao anterior acessando a mesma tabela que a paginaEsta cadastrando.Mas esta com um comportamento estranho:1o mostra uma tela de cadastro e ao cadastrar mostra a lista dos cadastrados.Porque ?Se quisermos entrar direto na lista completa precisamos acessar pelo seguinte endereco na url :http://localhost:8080/SpringLesson08-SpringStruts/RedirectContato.doe o link p/ acessa a pagina criada pelo NB+Struts hello, por esse http://localhost:8080/SpringLesson08-SpringStruts/Welcome.doComo acertamos isso ? Bom tem centenas de jeitos, vamos fazer o mais simples 1oI) defina como index.html no arquivo web.xml<welcome-file-list> <welcome-file>index.html</welcome-file></welcome-file-list>e no index.html aponte p/ o mapping desejado : <html> <head> <title></title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> </head> <body> <script type="text/javascript"> location.href='/SpringLesson08-SpringStruts/RedirectContato.do'; </script> </body></html>II) Salve os arquivos, o NB automaticamente faz o Deploy da app,clique em Run. veja se o apontamento do arquivo html funcionou.Vou fornecer a versao 1 do projeto como esta ate aqui.SpringLesson08-SpringStruts-v14) Implementando o Spring ao projeto com o struts.1) adicione a lib do spring ao projetoFigura 36 - Adicionando a lib do Spring2) altere o struts-config.xmlXml<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.3//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_3.dtd"><struts-config> <form-beans> <form-bean name="contatoForm" type="com.myapp.action.ContatoForm"> </form-bean> </form-beans> <global-exceptions> <exception type="java.lang.Exception" key="user.global.ex" path="/error.jsp" /> </global-exceptions> <global-forwards> <forward name="welcome" path="/Welcome.do"/> </global-forwards> <action-mappings> <action path="/Welcome" forward="/welcomeStruts.jsp"/> <action path="/RedirectContato"> <forward name="sucess" path="/index.jsp"> </forward> </action> <action path="/CreateContato" name="contatoForm" input="/RedirectContato.do"> <forward name="list" path="/RedirectContato.do"> </forward> </action><!-- renomeado apos adicionar o spring <action path="/CreateContato" type="com.myapp.action.CreateContatoAction" name="contatoForm" input="/RedirectContato.do"> <forward name="list" path="/RedirectContato.do"> </forward> </action> <action path="/RedirectContato" type="com.myapp.action.RedirectContatoAction"> <forward name="sucess" path="/index.jsp"> </forward> </action> --> <!-- samples <action path="/" type="com.myapp." name="" scope="" validate="" input="" /> </action-mappings> --> </action-mappings> <controller> <set-property property="processorClass" value="org.springframework.web.struts.DelegatingRequestProcessor" /> </controller> <message-resources parameter="MessageResources"/> <plug-in className="org.springframework.web.struts.ContextLoaderPlugIn" > </plug-in> <!-- <controller processorClass="org.apache.struts.tiles.TilesRequestProcessor"/> <message-resources parameter="com/myapp/struts/ApplicationResource"/> <plug-in className="org.apache.struts.tiles.TilesPlugin" > <set-property property="definitions-config"