This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Struts and the fly likes Handling multiple form data in struts2 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Handling multiple form data in struts2" Watch "Handling multiple form data in struts2" New topic
Author

Handling multiple form data in struts2

kish kumar
Ranch Hand

Joined: Jan 03, 2008
Posts: 54
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
Dishpal Bhaluja
Ranch Hand

Joined: Dec 30, 2007
Posts: 96
I hope


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

Will solve your issue

jaladhi dave
Greenhorn

Joined: Apr 26, 2011
Posts: 3
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>







 
 
subject: Handling multiple form data in struts2
 
Similar Threads
clearing HTML form fields after return from struts validation with errors
problem with struts1.1 please help me...
how to upload using html or javascript?
Multiple calls to populate ActionForm
Mainitaining State Between Requests - Struts