1 / 15

Struts2

Marco Antonio Abril 2009. Struts2. Configuração. Criar o Dynamic Web Project conforme a imagem. Baixar as bibliotecas do Struts2 de http://marcoreis.net/BibliotecasStruts2.zip . Criar o diretório lib e descompactar as bibliotecas. Logo em seguida, adicione-as no Build Path.

ziv
Download Presentation

Struts2

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Marco Antonio Abril 2009 Struts2

  2. Configuração Criar o Dynamic Web Project conforme a imagem. Baixar as bibliotecas do Struts2 de http://marcoreis.net/BibliotecasStruts2.zip. Criar o diretório lib e descompactar as bibliotecas. Logo em seguida, adicione-as no Build Path. Adicione todas as bibliotecas no servidor (Tomcat). Crie os arquivos package.properties, struts.xml, struts-modulo-gerente.xml no src do projeto. Os demais arquivos serão criados por demanda.

  3. web.xml <?xmlversion="1.0"encoding="UTF-8"?> <web-appxmlns: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>SistemaBancarioStruts2Web-</display-name> <filter> <filter-name>struts2</filter-name> <filter-class> org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class> <init-param> <param-name>actionPackages</param-name> <param-value>com.sistemabancario.apresentacao</param-value> </init-param> </filter>

  4. web.xml <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <welcome-file-list> <welcome-file>index.html</welcome-file> </welcome-file-list> </web-app>

  5. index.html <html> <bodyonload="window.location='sb/TelaDeLogin.action'"> Carregando... </body> </html>

  6. TelaPrincipal.jsp <%@taglibprefix="s"uri="/struts-tags"%> <%@pagelanguage="java"contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <!DOCTYPEhtmlPUBLIC"-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <linkhref="<s:urlvalue='css/Estilo.css'/>" rel="stylesheet" type="text/css"/> <metahttp-equiv="Content-Type"content="text/html; charset=ISO-8859-1"> <title>.:SistemaBancario:.</title> </head> <body>

  7. TelaPrincipal.jsp <!-- Iniciodapagina --> <tablealign="center"> <tr> <td><s:urlid="cadastro"action="TelaCadastroDeGerente"/><s:a href="%{cadastro}">CadastrodeGerente</s:a> ||</td> <td><s:urlid="cadastro"action="TelaConsultaGerentes"/><s:a href="%{cadastro}">ConsultaGerente</s:a></td> </tr> </table> <tablealign="center"> <tr> <td> <h1><s:textname="mensagem.sistema"/></h1> </td> </tr> </table> <!-- Fimdapagina --> </body> </html>

  8. struts.xml <?xmlversion="1.0"encoding="UTF-8"?> <!DOCTYPEstrutsPUBLIC"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN""http://struts.apache.org/dtds/struts-2.0.dtd"> <struts> <constantname="struts.enable.DynamicMethodInvocation"value="false"/> <constantname="struts.devMode"value="false"/> <constantname="struts.custom.i18n.resources"value="package"/> <includefile="struts-modulo-gerente.xml"/> <packagename="apresentacao"namespace="/sb"extends="struts-default"> <actionname="TelaDeLogin"> <result>/Login.jsp</result> </action> </package> </struts>

  9. Login.jsp <%@taglibprefix="s"uri="/struts-tags"%> <%@pagelanguage="java"contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <!DOCTYPEhtmlPUBLIC"-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <metahttp-equiv="Content-Type"content="text/html; charset=ISO-8859-1"> <title><s:textname="login.titulo"/></title> </head> <body>

  10. Login.jsp <!-- Iniciodapagina --> <tableborder="1"align="center"> <tr> <td><s:form> <s:propertyvalue="getText('login.cabecalho')"/>(getText)‏ <br/> <s:textname="login.cabecalho"/> <br/> <s:labelname="mensagem"theme="simple"/> <br/> <s:textfieldname="usuario.login"label="Login:"/> <s:passwordname="usuario.senha"label="Senha:"/> <s:submitaction="BemVindo"value="Ok"/> </s:form></td> </tr> </table> <!-- Fimdapagina --> </body> </html>

  11. package.properties # mensagem.sistema=Bem-VindoaoSistemaBancario # login.titulo=Login-SistemaBancario login.cabecalho=Informeloginesenha(properties)‏

  12. Login.java package com.sistemabancario.apresentacao; import com.sistemabancario.entidades.*; publicclass LoginAction { private Usuario usuario; private String mensagem = "Informe login e senha (LoginAction)"; public Usuario getUsuario() { if (usuario == null) { usuario = new Usuario(); } returnusuario; } public String getMensagem() { returnmensagem; } publicvoid setMensagem(String mensagem) { this.mensagem = mensagem; }

  13. Login.java public String efetuarLogin() { if (getUsuario().getSenha().equals("senha")) { return"acessoLiberado"; } else { setMensagem("Senha inv‡lida"); return"acessoNaoLiberado"; } } }

  14. struts-modulo-gerente.xml <?xmlversion="1.0"encoding="UTF-8"?> <!DOCTYPEstrutsPUBLIC"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN""http://struts.apache.org/dtds/struts-2.0.dtd"> <struts> <packagename="gerente"namespace="/sb"extends="struts-default"> </package> </struts>

  15. Para rodar a aplicação O link para rodar a aplicação: http://localhost:8080/SistemaBancarioStruts2Web

More Related