Pessoal estou criando uma tela de login para usar no sistema que terei que fazer aqui na empresa… estou apenas fazendo como teste ainda. Eu nao sei como fazer a tela de alteração dos dados… EStou usando Eclipse, Struts e hibernate… Veja os meus codigos:
AlteraLoginAction---------------------------------------------------------------
package br.com.flexform.struts.action;
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;
import org.hibernate.Session;
import br.com.flexform.hibernate.HibernateFactory;
import br.com.flexform.hibernate.Login;
import br.com.flexform.hibernate.DAO.LoginDAO;
import br.com.flexform.struts.form.AlteraLoginForm;
public class AlteraLoginAction extends Action{
@Override
public ActionForward execute(ActionMapping map, ActionForm form, HttpServletRequest req, HttpServletResponse res) throws Exception {
Session session = new HibernateFactory().getSession();
AlteraLoginForm formulario = ((AlteraLoginForm) form);
Login login = formulario.getLog();
LoginDAO dao = new LoginDAO(session);
dao.atualiza(login);
return map.findForward("atualiza");
}
}
Veja o AlteraLoginForm------------------------------------------------------
package br.com.flexform.struts.form;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import br.com.flexform.hibernate.Login;
public class AlteraLoginForm extends ActionForm {
private Login log = new Login();
public Login getLog() {
return log;
}
public void setLog(Login log) {
this.log = log;
}
public void reset (ActionMapping map, HttpServletRequest req){
this.log= new Login();
System.out.println("Limpando o formulário");
}
}
Veja a minha Pagina Login.jsp----------------------------------------
<%@ taglib uri=“http://struts.apache.org/tags-html” prefix=“html”%>
html:html
Login Sistema Flex
WebFlex | |
Usuário: |
<html:text property=“log.nome”/> |
Senha: |
<html:password property=“log.senha” size=“15”/> |
html:submitCadastrar </html:submit> |
</body>
</html:html>
Veja o meu arquivo struts-config.xml-----------------------------------
<?xml version="1.0" encoding="ISO-8859-1" ?><form-beans>
<form-bean name="LoginForm" type="br.com.flexform.struts.form.LoginForm"></form-bean>
<form-bean name="Login" type="br.com.flexform.struts.form.LoginUserForm"></form-bean>
<form-bean name="remove" type="br.com.flexform.struts.form.RemoveLoginForm"></form-bean>
<form-bean name="atualiza" type="br.com.flexform.struts.form.AlteraLoginForm"></form-bean>
</form-beans>
<action-mappings>
<action path="/efetualogin" name="LoginForm" type="br.com.flexform.struts.action.LoginAction">
<forward name="ok" path="/ramal.jsp"/>
<forward name="error" path="/erro.jsp"/>
</action>
<action path="/novoLogin" name="Login" type="br.com.flexform.struts.action.AdicionaLoginAction" scope="request">
<forward name="ok" path="/lista.do"/>
<forward name="error" path="/erro.jsp"/>
</action>
<action path="/lista" name="Login2" type="br.com.flexform.struts.action.ListaTudo">
<forward name="lista" path="/listaUsuario.jsp"/>
<forward name="vazia" path="/listaVazia.jsp"/>
</action>
<action path="/removeLogin" name="remove" type="br.com.flexform.struts.action.RemoveLoginAction">
<forward name="remove" path="/lista.do"/>
</action>
<action path="/atualiza" name="atualiza" type="br.com.flexform.struts.action.AlteraLoginAction" scope="request">
<forward name="atualiza" path="/lista.do"/>
<forward name="error" path="/erro.jsp"/>
</action>
</action-mappings>
<message-resources parameter="MessageResources" />
Veja o Login----------------------------------------------------------
package br.com.flexform.hibernate;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
@Entity
public class Login {
@GeneratedValue
@Id
private int id;
@Column(nullable = true, length = 50)
private String nome;
@Column(nullable = true, length = 6)
private String senha;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public String getSenha() {
return senha;
}
public void setSenha(String senha) {
this.senha = senha;
}
}
Veja a minha classe LoginDAO-------------------------------------------
package br.com.flexform.hibernate.DAO;
import java.util.List;
import org.hibernate.Session;
import org.hibernate.Transaction;
import br.com.flexform.hibernate.Login;
public class LoginDAO {
private Session session;
public LoginDAO(Session session) {
this.session = session;
}
public void salva(Login log) {
Transaction transaction = session.beginTransaction();
this.session.save(log);
transaction.commit();
}
public void remove(Login log){
Transaction transaction = session.beginTransaction();
this.session.delete(log);
transaction.commit();
}
public void atualiza (Login log){
Transaction transaction = session.beginTransaction();
this.session.update(log);
transaction.commit();
}
public List<Login> ListaTudo(){
return this.session.createCriteria(Login.class).list();
}
}
Por favor me deem ideia para fazer um sistema bom para login, pois pretendoutiliza-lo na WEB…