This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Struts and the fly likes How to use struts to display initial data in JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Frameworks » Struts
Bookmark "How to use struts to display initial data in JSP" Watch "How to use struts to display initial data in JSP" New topic
Author

How to use struts to display initial data in JSP

Nuwan Priyadarshana
Greenhorn

Joined: Aug 27, 2005
Posts: 26
I am new to struts, in my application each JSP page display data when initially load the JSP page, so how can I use struts to do that?


Nuwan<br />SCJP 1.5(83), SCWCD 1.4(86) <br/>
www.saralasolutions.com
rakshini nithya
Ranch Hand

Joined: Jun 15, 2006
Posts: 39
package com.example;

import java.util.ArrayList;
import java.util.List;

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;

public final class SubmitAction extends Action
{

public ActionForward perform(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
{
String param = mapping.getParameter();
if( param.equalsIgnoreCase("load") )
{
SubmitForm submitform = (SubmitForm) form;
submitform.setFirstName("Kamesh");
submitform.setLastName("loganathan");

AddressBean addressBean = submitform.getAddressBean();

addressBean.setStreet1("Taramani,");
addressBean.setStreet2("Tidel Park");
addressBean.setCity("Chennai");
addressBean.setState("
rakshini nithya
Ranch Hand

Joined: Jun 15, 2006
Posts: 39
package com.example;

import java.util.ArrayList;
import java.util.List;

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;

public final class SubmitAction extends Action
{

public ActionForward perform(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
{
String param = mapping.getParameter();
if( param.equalsIgnoreCase("load") )
{
SubmitForm submitform = (SubmitForm) form;
submitform.setFirstName("Kamesh");
submitform.setLastName("loganathan");

AddressBean addressBean = submitform.getAddressBean();

addressBean.setStreet1("Taramani,");
addressBean.setStreet2("Tidel Park");
addressBean.setCity("Chennai");
addressBean.setState("TN");

PhoneBean phoneBean1 = new PhoneBean();
phoneBean1.setAreaCode("044");
phoneBean1.setPhone("24753044");
phoneBean1.setMobile("9884487517");
PhoneBean phoneBean2 = new PhoneBean();
phoneBean2.setAreaCode("2044");
phoneBean2.setPhone("224753044");
phoneBean2.setMobile("29884487517");
List phoneList = new ArrayList();
phoneList.add(phoneBean1);
phoneList.add(phoneBean2);

addressBean.setPhoneBeanArray(phoneList);

submitform.setAddressBean(addressBean);
}
// Forward control to the specified success target
return (mapping.findForward("success"));
}
}
ans specify the parameter in struts config.xml also like this
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE struts-config (View Source for full doctype...)>
- <struts-config>
- <!-- ========== Form Bean Definitions =================
-->
- <form-beans type="org.apache.struts.action.ActionFormBean">
<form-bean name="submitForm" type="com.example.SubmitForm" />
</form-beans>
- <!-- ========== Global forwards ============
-->
- <global-forwards type="org.apache.struts.action.ActionForward">
<forward name="first" path="/submit.jsp" />
</global-forwards>
- <!-- ========== Action Mapping Definitions ============
-->
- <action-mappings type="org.apache.struts.action.ActionMapping">
- <action path="/start" type="com.example.SubmitAction" name="submitForm" attribute="FormBean" scope="session" parameter="load">
<forward name="success" path="/submit.jsp" />
<forward name="failure" path="/submit.jsp" />
</action>
- <action path="/submit" type="com.example.SubmitAction" name="submitForm" attribute="FormBean" input="/submit.jsp" scope="session" parameter="display">
<forward name="success" path="/success.jsp" />
<forward name="failure" path="/submit.jsp" />
</action>
</action-mappings>
</struts-config>
Nuwan Priyadarshana
Greenhorn

Joined: Aug 27, 2005
Posts: 26
Thanks rakshini
 
Have you checked out Aspose?
 
subject: How to use struts to display initial data in JSP
 
It's not a secret anymore!