ArrayList<Contato>(); private ContatoDAO contatoDAO = new ContatoDAOImpl(); @Override public Contato getModel() { return contato; } public String saveOrUpdate() { contatoDAO.saveOrUpdateContato(contato); return SUCCESS; } /** * To list all contatos. * * @return String */ public String list() { contatoList = contatoDAO.listContato(); return SUCCESS; } /** * To delete a contato. * * @return String */ public String delete() { HttpServletRequest request = (HttpServletRequest) ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST); contatoDAO.deleteContato(Integer.parseInt(request.getParameter("id"))); return SUCCESS; } /** * To list a single contato by Id. * * @return String */ public String edit() { HttpServletRequest request = (HttpServletRequest) ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST); contato = contatoDAO.listContatoById(Integer.parseInt(request.getParameter("id"))); return SUCCESS; } public Contato getContato() { return contato; } public void setContato(Contato contato) { this.contato = contato; } public List<Contato> getContatoList() { return contatoList; } public void setContatoList(List<Contato> contatoList) { this.contatoList = contatoList; }}8) Criando os arquivos XML struts.xml e web.xmlFigura 30- Implementando os arquivos XMLsrc/struts.xml :<!DOCTYPE struts PUBLIC"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN""http://struts.apache.org/dtds/struts-2.0.dtd"><struts> <package name="default" extends="hibernate-default"> <action name="saveOrUpdateContato" method="saveOrUpdate" class="com.springlesson09.service.ContatoAction"> <result name="success" type="redirect">listContato</result> </action> <action name="listContato" method="list" class="com.springlesson09.service.ContatoAction"> <result name="success">/register.jsp</result> </action> <action name="editContato" method="edit" class="com.springlesson09.service.ContatoAction"> <result name="success">/register.jsp</result> </action> <action name="deleteContato" method="delete" class="com.springlesson09.service.ContatoAction"> <result name="success" type="redirect">listContato</result> </action> </package></struts>WEB-INF/web.xml :<?xml version="1.0" encoding="UTF-8"?><web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"> <display-name>Struts2Example19</display-name> <filter> <filter-name>struts2</filter-name> <filter-class> org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter </filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list></web-app>O NB ja deve ter criado os arquivo XML context.xml e o beans.xml:META-INF/context.xml <?xml version="1.0" encoding="UTF-8"?><Context antiJARLocking="true" path="/SpringLesson09"/>WEB-INF/beans.xml:<?xml version="1.0" encoding="UTF-8"?><beans 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/beans_1_0.xsd"></beans>Remova a lib do Hibernate que o NB adicionouFigura 31- Limpe o que o NB adicionoue deixe apenas as utilizadas.Figura 32- Limpeza das biblotecas9) Criando os arquivos jsp e cssI) acertemos o index.jsp que o NB criou :index.jsp :<%@page contentType="text/html" pageEncoding="UTF-8"%><%@taglib uri="/struts-tags" prefix="s"%><!DOCTYPE html><html> <head> <title></title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> </head> <body> <script type="text/javascript"> location.href='/SpringLesson09/listContato'; </script> </body></html>II)register.jsp<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><%@taglib uri="/struts-tags" prefix="s"%><html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Novo Contato</title> <s:head /> <style type="text/css"> @import url(style.css); </style> </head> <body> <s:form action="saveOrUpdateContato"> <s:push value="contato"> <s:hidden name="id" /> <s:textfield name="nome" label="Nome" /> <s:textfield name="telefone" label="Fone" /> <s:textfield name="email" label="Email" /> <s:submit /> </s:push> </s:form> <s:if test="contatoList.size() > 0"> <div class="content"> <table class="contatoTable" cellpadding="5px"> <tr class="even"> <th>Nome</th> <th>Fone</th> <th>Email</th> <th>&nbsp;</th> <th>&nbsp;</th> </tr> <s:iterator value="contatoList" status="contatoStatus"> <tr class="<s:if test="#contatoStatus.odd == true ">odd</s:if><s:else>even</s:else>"> <td><s:property value="nome" /></td> <td><s:property value="telefone" /></td> <td><s:property value="email" /></td> <td><s:url id="editURL" action="editContato"> <s:param name="id" value="%{id}"></s:param> </s:url> <s:a href="%{editURL}">Edit</s:a></td> <td><s:url id="deleteURL" action="deleteContato"> <s:param name="id" value="%{id}"></s:param> </s:url> <s:a href="%{deleteURL}">Delete</s:a></td> </tr> </s:iterator> </table> </div> </s:if> </body></html>III) o style.css@CHARSET "ISO-8859-1";.content {font-family: sans-serif;font-size: small;}.userTable { border-width: 1px 1px 1px 1px; border-spacing: 2px; border-style: outset outset outset outset; border-color: black black black black; border-collapse: collapse;}.userTable td { border-width: 1px 1px 1px 1px; border-spacing: 2px; border-style: outset outset outset outset; border-color: black black black black; border-collapse: collapse;}.userTable th { border-width: 1px 1px 1px 1px; border-spacing: 2px; border-style: outset outset outset outset; border-color: black black black black; border-collapse: collapse; background-color: rgb(255, 255, 255);}.odd {background-color: #FFFFF0;}.even {background-color: #FAF0E6;}10) Conferindo a estrutura do projeto :Figura 33- Visao do projeto11) Testando Figura 34-1o Teste sem utilizar as DI SpringObserve o Log :INFO: No Spring WebApplicationInitializer types detected on classpathOct 2, 2012 8:46:08 PM org.apache.catalina.core.ApplicationContext logINFO: Initializing Spring root