• Post Reply Bookmark Topic Watch Topic
  • New Topic

how do I pass data from one JSP to another

 
sarika Gupta
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I m having a problem passing this data to a new JSP.
please help me.plz give some example of code.
 
ravindra kumar
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
May I know what is the problem ??

BTW, You can pass the data by sending info through query string, setting the info into session or if You are forwarding to the second jsp through parameter tags.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How are you getting to the new JSP, form submission, sendRedirect, hyperlink?
If you describe what it is you're trying to do in a little more detail, we may be able to help you.
 
sarika Gupta
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
i want to get new JSP at the time of form submission,
If you describe it with the help of coding it is easy to understand me.
 
Kapil Shrivastava
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

please give me ur scenireo???
 
sarika Gupta
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
i have done one page that handle all databse related events
and one is JSP page in between a hidden page that handle the some action so
the time of execugtion will reduce.

i send u some code of db handler and hidden page


this is hidden page
<%
String mode = request.getParameter("mode");
String userId = (String)session.getAttribute("User");

ArrayList guser = new ArrayList();


guser.add(0,request.getParameter("mode"));
guser.add(1,request.getParameter("userId"));
guser.add(2,request.getParameter("userName"));
guser.add(3,request.getParameter("password"));
guser.add(4,request.getParameter("department"));
guser.add(5,request.getParameter("companyName"));
guser.add(6,request.getParameter("level"));
guser.add(7,request.getParameter("Status"));

boolean successFlag = false;
DBHandler dbh = new DBHandler();
if(mode.equalsIgnoreCase("modify"))
{
successFlag = dbh.modifyguser(guser);
if(successFlag = true)
{
%>
<jsp:forward page="menuAdmin.jsp"/>
<%
}
else
{
throw new AppException("error Insert");
}





this is db handler page

public boolean modifyguser(ArrayList guser)
{
boolean flag = false;
getConnection();

String mode = (String) guser.get(0);
String userId = (String)guser.get(1);
String userName = (String) guser.get(2);
String password = (String) guser.get(3);
String department = (String) guser.get(4);
String companyName = (String) guser.get(5);
String level = (String) guser.get(6);
String Status = (String) guser.get(7);
try
{
Statement st = con.createStatement();

String Query ="select mst01_company,mst01_uid,mst01_user_name,mst01_pwd,mst01_dept,mst01_user_lvl,mst01_status from mst01_user where mst01_uid ='"+userId+"'";

ResultSet rs = st.executeQuery(Query);
flag = true;
while(rs.next())
{
companyName = rs.getString(1);
userId = rs.getString(2);
userName = rs.getString(3);
password = rs.getString(4);
department = rs.getString(5);
level = rs.getString(6);
Status = rs.getString(7);
}
}
catch (SQLException ex)
{
ex.printStackTrace();
}

}
return flag;
}
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you're chaining pages together with jsp:forward, you can bind your variables to request scope with request.setAttribute and then retrieve them in the next JSP with request.getAttribute.



===================================

By the way...
UBB Code tags around your posted code will make it much more readable and thus , more likely to be read by someone who could help you.
[ May 20, 2005: Message edited by: Ben Souther ]
 
sarika Gupta
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Thanks for ur kind suggestion.Can u give some example of code.
so it is easy to understand me.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sarika Gupta ,

JavaRanch is a community of people from all over the world, many of who are not native English speakers. While using abbreviations like "u" instead of spelling out "you" is convenient when text messaging your friends on a cell phone or in a chat room, it presents an extra challenge to those that are already struggling with English. Additionally, such shortcuts may confound automated translation tools that patrons of the Ranch may be making use of.

I would like to ask for your help in making the content of JavaRanch a little easier to read for everybody that visits here by not using such abbreviations.

Please read this for more information.

thanks,
bear
Forum Bartender
 
sarika Gupta
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Sorry for this mistake,I always remember this will not go again.
and a thanks for your suggestion.
 
Kumar Navin
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sarika,
Did you ever tried RequestDispatcher interface. It has the facility of passing on the request object and then the information be retrieved on the page before a response is sent.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Kumar Navin:
Sarika,
Did you ever tried RequestDispatcher interface. It has the facility of passing on the request object and then the information be retrieved on the page before a response is sent.


He's using jsp:forward which uses a requestDispatcher in the generated servlet code.
<jsp:forward page="menuAdmin.jsp"/>
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!