Aim:
The < bean:write > tag gets the value of a named bean property. This tag uses the attributes, namely, name, property, and scope. The value specified by the attributes will be output to the JSPWriter
The < bean:message > tag gets value from ApplicationResource.properties.
Procedure:
Step_1: Create actionforms
Step_2: Create actions
Step_3: Create jsp file
Step_4: Change in struts-config.xml file
Step_5: Run the file
Step_1:
Create actionforms (BeanForms)
Include following code
package actionforms;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
public class BeanForms extends org.apache.struts.action.ActionForm
{
private String name;
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
}
Step_2:
Create action(BeanActions)
Include following coding
package actions;
import actionforms.BeanForms;
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 BeanActions extends org.apache.struts.action.Action
{
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception
{
BeanForms sform=(BeanForms)form;
return mapping.findForward("bean");
}
}
Step_3:
Create Input.jsp file
Include following coding
< %@taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" % >
< %@taglib uri="/WEB-INF/struts-html.tld" prefix="html" % >
< %@taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" % >
< html >
< head >
< title > JSP Page For Input < /title >
< /head >
< body >
< html:form action="/bean" >
< bean:message key=”struts.name” > < html:text property="name"/ >
< html:submit value="OK"/ >
< /html:form >
< /body >
< /html >
Create Output.jsp file
Include following code
< %@taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" % >
< %@taglib uri="/WEB-INF/struts-html.tld" prefix="html" % >
< %@taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" % >
< html >
< head >
< title > JSP Page For Input < /title >
< /head >
< body >
< bean:write property="name" name="BeanForms"/ >
< /body >
< /html >
Step_4:
Made change in struts-config.xml
……..
< action-mappings >
< action input="/" name="BeanForms" path="/bean" scope="session" type="actions.BeanActions" >
< forward name="bean" path="/jsp/Output.jsp"/ >
< /action >
< /action-mappings >
…….
Step_5:
Include struts.name=Name in ApplicationResource.properties
Step_6:
Run Input.jsp
Conclusion:
From this,we can understand how to write the output using < bean:write > tag in struts framework.
No comments:
Post a Comment