This week's book giveaway is in the Spring forum.
We're giving away four copies of Spring Boot in Practice and have Somnath Musib on-line!
See this thread for details.
Win a copy of Spring Boot in Practice this week in the Spring forum!
  • 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
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

Handling multiple form data in struts2

 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
I have a requirement that in first jsp namely NameCollector1.jsp i enter a field value and once i click on next it goes to next jsp NameCollector2.jsp which again accept a field value from user.
now once i submit NameCollector2.jsp after entering value in the action only NameCollector2.jsp values is coming but the value entered in ameCollector1.jsp is missing.
How to bring both values entered in NameCollector1.jsp and NameCollector2.jsp in to action
 
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I hope


https://coderanch.com/t/59514/Struts/Classic-Struts-Issue-beginner

Will solve your issue

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i show you the code for your problem and you will get the idea...

Action:-

package com.stikiflem;

import java.util.Map;

import org.apache.struts2.interceptor.SessionAware;

import com.opensymphony.xwork2.ActionSupport;

public class ForwordAction extends ActionSupport implements SessionAware
{
private String userName;
private String password;
private Map session;

public String getUserName()
{
return userName;
}


public void setUserName(String userName)
{
this.userName = userName;
}


public String getPassword()
{
return password;
}


public void setPassword(String password)
{
this.password = password;
}

public String forword()
{
session.put("username", getUserName());
// setUserName(userName);

return "success";
}

public String execute()
{
userName=(String)session.get("username");

setUserName(userName);
setPassword(password);
return SUCCESS;
}


public Map getSession()
{
return session;
}


public void setSession(Map session)
{
this.session = session;
}

}


1st jsp page


<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ taglib prefix="s" uri="/struts-tags" %>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form action="ForwordAction.action">

<input type="text" name="userName"/>

<input type="submit" value="Next" id="submit"><br>

</form>
</body>
</html>

2nd jps page


<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ taglib prefix="s" uri="/struts-tags" %>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>

<form action="NextAction.action">

<input type="text" name="password"/>

<input type="submit" value="submit" id="submit"><br>
<s:property value="userName"/>
</form>
</body>
</html>

3rd jsp page



<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ taglib prefix="s" uri="/struts-tags" %>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>

<s:property value="userName"/>
<s:property value="password"/>

</form>
</body>
</html>

Struts.xml

<action name="ForwordAction" class="com.stikiflem.ForwordAction" method="forword">
<result name="success">Next.jsp</result>
</action>

<action name="NextAction" class="com.stikiflem.ForwordAction">
<result name="success">success.jsp</result>
</action>







 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic