struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Anjib Mulepati <anji...@hotmail.com>
Subject Re: [S 1.3.8] Simple Struts Example
Date Fri, 28 Jan 2011 14:50:56 GMT
Can anyone help to get this simple program run?

Thanks
Anjib
On 1/27/2011 4:37 PM, Anjib Mulepati wrote:
> 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-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>>
>


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


Mime
View raw message