• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

How to use struts to display initial data in JSP

 
Nuwan Priyadarshana
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
rakshini nithya
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks rakshini
 
If you're gonna buy things, buy this thing and I get a fat kickback:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic