cara como faço para colocar o valor de um bean em um actionform e retornar para uma jsp?
(nao sei se expliquei bem mas o codigo e bem simples)
mais simplificado: chamo teste.do do browser e gostaria de receber o nome da ide que setei pelo ActionMapping mapping
so consigo receber a constante : “ideTESTE”; que e automaticamnte setada no actionForm.
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.2//EN"
"http://jakarta.apache.org/struts/dtds/struts-config_1_2.dtd">
<struts-config>
<form-beans>
<form-bean name="ideForm" type="teste.IdeForm" />
<form-bean name="UsuarioForm" type="teste.UsuarioForm" />
</form-beans>
<global-exceptions>
</global-exceptions>
<global-forwards>
<forward name="welcome" path="/Welcome.do"/>
</global-forwards>
<action-mappings>
<action path="/Welcome" forward="/welcomeStruts.jsp"/>
<action path="/teste" type="teste.testeAction" name="ideForm" parameter="dispatch"
scope="request">
<forward name="ok" path="/ok.jsp" />
</action>
</action-mappings>
<message-resources parameter="com/myapp/struts/ApplicationResource"/>
</struts-config>
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package teste;
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 teste.IdeForm;
/**
*
* @author ism
*/
public class testeAction extends Action {
public ActionForward execute(ActionMapping mapping,ActionForm form, HttpServletRequest request,HttpServletResponse response)
{
IdeForm ide = (IdeForm) form;
ide.setNomeIDE("netbeans"); // nao consigo obter este valor
return mapping.findForward("ok");
}
}
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@taglib uri="/WEB-INF/struts-logic.tld" prefix="logic"%>
<%--
Document : ok
Created on : 24/11/2008, 15:53:29
Author : ism
--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
testando
<br>nome IDE = ${ideform.nomeIDE},<br> testeIDE=${ideForm.teste} ,<br> teste usuario = ${UsuarioForm.teste} ,<br>nome Usuario = ${UsuarioForm.nome} </h1>
</body>
</html>
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package teste;
import org.apache.struts.action.ActionForm;
/**
*
* @author ism
*/
public class IdeForm extends ActionForm {
private String nomeIDE;
public void setNomeIDE(String nomeIDE) {
this.nomeIDE = nomeIDE;
}
public String getNomeIDE() {
return nomeIDE;
}
public IdeForm() {
}
public IdeForm(String nomeIDE) {
this.nomeIDE = nomeIDE;
}
public String getTeste()
{
return "ideTeste";
}
}
package teste;
import org.apache.struts.action.ActionForm;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author ism
*/
public class UsuarioForm extends ActionForm {
private String nome;
public UsuarioForm() {
}
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public String getTeste(){
return "testeUsuario";
}
}