1. JSP Files
=========
a) Calling page
---------------------
<%@ taglib uri="http://struts.apache.org/tags-bean"; prefix="bean" %>
<%@ taglib uri="http://struts.apache.org/tags-html"; prefix="html" %>
<%@ taglib uri="http://struts.apache.org/tags-logic"; prefix="logic" %>

<html:html lang="true">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title><bean:message key="welcome.title"/></title>
</head>
<body style="background-color: white">
<form  action="getValue.do" method="post">
<input type="submit" value="Get Value" />
</form>
</body>
</html:html>

b) Result Page
-------------------
<%@ taglib uri="/WEB-INF/struts-bean.tld"  prefix="bean" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1>result</h1>
<jsp:useBean id="exchangeBean" scope="session" class="com.anjib.beans.DataBean" />
<jsp:getProperty name="exchangeBean" property="sampleProperty" />

</body>
</html>

2. Bean Class
===========
package com.anjib.beans;

import java.io.Serializable;

public class DataBean implements Serializable {

    private String sampleProperty;

    public DataBean() {

    }

    public String getSampleProperty() {
        return sampleProperty;
    }

    public void setSampleProperty(String value) {
        this.sampleProperty = value;
    }
}

3. Action Class
============
package com.anjib.actions;

import com.anjib.beans.DataBean;
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;

public class GetValueAction extends org.apache.struts.action.Action {

      private static final String SUCCESS = "success";

     @Override
    public ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        DataBean myBean = new DataBean();
        myBean.setSampleProperty("Anjib");
        System.out.println("Bean Value: " + myBean.getSampleProperty());
        return mapping.findForward(SUCCESS);
    }
}

When I run this app I get null as result.

On 1/27/2011 4:16 PM, Anjib Mulepati wrote:
Hi All,

I am looking for the simple example of using beans and tag in Struts to avoid using scriptlets. I am trying to get concept of using tag to access result from back end using the beans. It will be very helpful if some one can provide me a link or example which I can look into.

Thanks
Anjib





---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org





---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org

Reply via email to