Para explicar minhas dúvidas vou usar um exemplo bem simples:
struts-config.xml:
[code]<?xml version="1.0" encoding="windows-1252" ?>
[/code]Página em JSP:
[code]
<%@ page contentType=“text/html;charset=windows-1252”%>
<%@ taglib uri=“http://jakarta.apache.org/struts/tags-html” prefix=“html”%>
Teste de Login
<html:form action=“logon.do” method=“POST”>
Nome <html:text property=“login” size=“20” maxlength=“10”/>
Sobrenome <html:password property=“senha” size=“20” maxlength=“10”/>
<html:submit property=“ok”/>
</html:form>
[/code]Minha classe Acesso.java:
[code]package form;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForm;
public class Acesso extends ActionForm {
private String login="";
private String senha="";
public Acesso() {
}
public void reset(ActionMapping actionMapping, HttpServletRequest request) {
this.login="";
this.senha="";
}
public ActionErrors validate(ActionMapping actionMapping, HttpServletRequest request) {
ActionErrors errs = new ActionErrors();
return errs;
}
public void setLogin(String login) {
this.login = login;
}
public String getLogin() {
return login;
}
public void setSenha(String senha) {
this.senha = senha;
}
public String getSenha() {
return senha;
}
}[/code]
Meu action
ActionLogin.java:
[code]package action;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import form.Acesso;
import manager.valida;
public class ActionLogin extends org.apache.struts.action.Action {
Acesso ac = new Acesso();
valida va = new valida();
private static final String FORWARD_acesso = “index”;
private static final String FORWARD_volta= "volta";
public ActionLogin() {
}
public ActionForward execute(ActionMapping ActionMapping,
ActionForm ActionForm,
HttpServletRequest HttpServletRequest,
HttpServletResponse HttpServletResponse) throws Exception {
String login = ac.getLogin();
String senha = ac.getSenha();
if(va.verificaSenha(login,senha)){
return ActionMapping.findForward(FORWARD_acesso);
}
else{
return
ActionMapping.findForward(FORWARD_volta);}
}
}[/code]
E por último meu valida:
valida.java
[code]package manager;
public class valida{
public boolean
verificaSenha(String nome,String senha){
if(nome.compareTo("pedro")==0){
return true;
}else if (senha.compareTo("1234")==0){
return true;
}
else{
return false;
}
}
}
[/code]
1º Dúvida: Minha classe Acesso, onde fica meus gets e sets, não está pegando os valores do formulário. Pq o motivo??? Aparentemente está td certo.
2º Dúvida: Pq tem códigos de exemplo que eu vejo que tem html:html e tem uns que apenas usa taglib apenas dentro do form, como este exemplo??? O certo é usar taglib em tudo, como no body e no head(ficando html:body e html:head), ou só no form mesmo??