Struts 2 com Bootstrap

Projeto feito com Strust 2, Bootstrap e CRUD completo

Cliente.java
package entity;

public class Cliente {

	private Integer idCliente;	
	private String  nome;	
	private String email;
	//alt + s generate getter and settes
	//alt + S construtor vazio
	//alt + s
	
	public Cliente() {
	}	
	
	public Cliente(Integer idCliente, String nome, String email) {
		super();
		this.idCliente = idCliente;
		this.nome = nome;
		this.email = email;
	}
	
	@Override
	public String toString() {
		return "Cliente [idCliente=" + idCliente + ", nome=" + nome + ", email=" + email + "]";
	}


	public Integer getIdCliente() {
		return idCliente;
	}
	public void setIdCliente(Integer idCliente) {
		this.idCliente = idCliente;
	}
	public String getNome() {
		return nome;
	}
	public void setNome(String nome) {
		this.nome = nome;
	}
	public String getEmail() {
		return email;
	}
	public void setEmail(String email) {
		this.email = email;
	}
}
				
ClienteDao.java
package persistence;

import java.util.ArrayList;
import java.util.List;
import entity.Cliente;

public class ClienteDao extends Dao {

	public void create(Cliente c)throws Exception{
		open();
			stmt = con.prepareStatement("insert into cliente values (null,?,?)");
			stmt.setString(1, c.getNome());
			stmt.setString(2, c.getEmail());
			stmt.execute();
			stmt.close();
		close();
	}
	
	public List  findAll() throws Exception{
		open();
			stmt = con.prepareStatement("select * from cliente");
			rs = stmt.executeQuery();
			List lista= new ArrayList();
			while(rs.next()){
				Cliente c = new Cliente();
				c.setIdCliente(rs.getInt(1));
				c.setNome(rs.getString(2));
				c.setEmail(rs.getString(3));
				lista.add(c);
			}
		close();
		return lista;
	}
	
	public Cliente findByCode(Integer cod) throws Exception{
		open();
			stmt = con.prepareStatement("select * from cliente where idCliente=?");
			stmt.setInt(1, cod);
			rs  = stmt.executeQuery();
			Cliente c = null;
			if (rs.next()){
			c = new Cliente(rs.getInt(1), rs.getString(2), rs.getString(3));
			}
		close();
		return c;
	}	
	
	public void update(Cliente c) throws Exception{
		open(); 
			stmt = con.prepareStatement("update cliente set nome=?, email=? where idCliente=?");
			stmt.setString(1, c.getNome());
			stmt.setString(2, c.getEmail());
			stmt.setInt(3, c.getIdCliente());
			stmt.execute();
			stmt.close();
		close();
	}	
	
	public void delete(Integer cod)throws Exception{
	open();
		stmt = con.prepareStatement("delete from cliente where idCliente=?");
		stmt.setInt(1, cod);
		stmt.execute();
		stmt.close();
	close();  
	}
}
							
ClienteAction.java
package control;

import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts2.ServletActionContext;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import entity.Cliente;
import persistence.ClienteDao;

public class ClienteAction extends ActionSupport implements ModelDriven{

	private static final long serialVersionUID = 1L;	
	private Cliente cliente; //Olha o Cliente aquiespaço para o Cliente
	private List lista; //criar a lista 
	
	@Override
	public Cliente getModel() {
		return cliente;
	}
	
	//espaço de Mem para o Cliente
	
	public ClienteAction() {
		cliente = new Cliente();
		lista = new ArrayList(); //inicia no Construtor
	}	
	
	public Cliente getCliente() {
		return cliente;
	}
	public void setCliente(Cliente cliente) {
		this.cliente = cliente;
	}
	public static long getSerialversionuid() {
		return serialVersionUID;
	}
	
	public List getLista() {
		try{
			lista = new ClienteDao().findAll();	
		}catch(Exception ex){
			ex.printStackTrace();
		}
		return lista;
	}
		//Estou chamando os Dados do Banco no getLista ...

	public void setLista(List lista) {
		this.lista = lista;
	}

	public String cadastrar(){
		HttpServletRequest request= (HttpServletRequest) ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);
		//Padrão de Envio de Mensagem)
		try{	    
		ClienteDao cd = new ClienteDao();
			cd.create(cliente); //grava
			cliente = new Cliente(); //Limpa	     
		request.setAttribute("msg", "Cliente Cadastrado com Sucesso");
		//Mensagem ...
		}catch(Exception ex){
			ex.printStackTrace();
		}
		return SUCCESS;
	}
	
	public String listar(){
		return SUCCESS;
	}
	
	public String excluir(){
		try{
			HttpServletRequest request = (HttpServletRequest)
		ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);
		ClienteDao cd = new ClienteDao();		
		int id = new Integer (request.getParameter("id"));
		cd.delete(id);
	request.
	setAttribute("msg", "Exclusao do Cliente realizado com Sucesso");	
		}catch(Exception ex){
			ex.printStackTrace();
		}
		return SUCCESS;
	}	
	
	public String editar(){
	HttpServletRequest request = (HttpServletRequest)
		ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);
		try{
		int id = new Integer(request.getParameter("id"));
		cliente =  new ClienteDao().findByCode(id);
		}catch(Exception ex){
			ex.printStackTrace();		
		}
		return SUCCESS;
	}
	
	public String alterar(){
		HttpServletRequest request = (HttpServletRequest)
			ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);
			try{
			ClienteDao cd = new ClienteDao();
			cd.update(cliente);
			lista = cd.findAll();
			request.setAttribute("msg"," Dados Alterados ...");
			}catch(Exception ex){
				ex.printStackTrace();		
			}
		return SUCCESS;
		}	
}  
sistema.jsp
<!DOCTYPE html>
<html>

<head>
	<%@taglib prefix="s" uri="/struts-tags" %>
	<link rel="stylesheet" href="css/bootstrap.css" />
	<script type="text/javascript" src="js/bootstrap.js" ></script>
</head>

<body>
	<div class="container">

	<div class="col-sm-offset-1 col-sm-10">
		<div class="jumbotron">
<center><h3>Cadastro de Cliente</h3></center>
		<br/>
		
		<ul class="nav nav-tabs">
			<li class="active"><a href="#">Cadastrar Cliente</a></li>
			<li><a href="cliente.listar.action">Consultar Cliente</a></li>
		</ul>
	<p/>       
	
	
	<div class="row">
	<s:form action="cliente.cadastrar" cssClass="form1">
		<div class="col-sm-10">
		<label>Nome:</label>
		<input type="text" class="form-control" name="cliente.nome" />
		</div>  
		<div class="col-sm-10">
		<label>Email:</label>
		<input type="text" class="form-control" name="cliente.email" />
	</div>  
	<div class="col-sm-10">
	<br/>
	<input type="submit" value="Cadastrar Cliente" class="btn btn-danger" />
	</div> 
	</s:form>
	</div>
	
	<div class="row">
	<br/>
	<br/>
	${msg}
	</div>
	
	</div>
	</div>
	</div>

</body>

</html> 
	

Rodando o sistema...

listar.jsp
<!DOCTYPE html>
<html>

<head>
 <%@taglib prefix="s" uri="/struts-tags" %>
 <link rel="stylesheet" href="css/bootstrap.css" />
 <script type="text/javascript" src="js/bootstrap.js" ></script>
</head>

<body>
   <div class="container">
      <div class="col-sm-12">
      
      <div class="jumbotron">
      <center><h3>Consulta de Clientes</h3></center>      	
      <br/>
      
          <ul class="nav nav-tabs">
           <li><a href="cliente.cadastrar.action">Cadastrar Cliente</a></li>
           <li class="active"><a href="#">Consultar Cliente</a></li>
        </ul>
         
          <table class="table table-hover">
            <thead>
             <tr>
               <td>Codigo</td>
               <td>Nome</td>
               <td>E-mail</td>
               <td>Excluir</td>
               <td>Alterar</td>
             </tr>
            </thead>
            
            <tbody>
          <s:iterator value="lista">
           <s:url id="excluir"  action="cliente.excluir">
                 <s:param name="id" value="%{idCliente}" />
           </s:url>
           
           <s:url id="editar" action="cliente.editar">
                 <s:param name="id" value="%{idCliente}" />
           </s:url>
              
               <tr>
               <td><s:property value="idCliente" /></td>
               <td><s:property value="nome" /></td>
               <td><s:property value="email" /></td>
         		<td>
         		<s:a href="%{excluir}" 
         		onclick="return confirm('deseja Excluir')">
         		<span class="glyphicon glyphicon-trash"></span>
         		</s:a>
         		</td>
         		
         		<td>
        	    <s:a href="%{editar}"> 
         		 <span class="glyphicon glyphicon-edit"></span>
         		</s:a> 
         		</td>
         		
               </tr>
             </s:iterator>
            </tbody>            
            
          </table>
      ${msg}    
      </div>
      
   </div>
   
   </div>
   <p/>
   
   

</body>

</html>  
							

Listando o sistema...

Editando...