Carrying values across jsp pages
hi there!
i got a quick question...
ive got a login page where users enter their email address and a password and upon pressing the submit button the login page calls the page processlogin.jsp which verifies this email addres and password with those values stored in the database.
a successful login then displays another page where users submit other details. this form then calls another process jsp page which stores this new information in another table in the database.
my question is how do i 'pass' through that initial email address the user enters on the login page through to this latter page....and inevitably...on to other pages too.
the reason i need to do this is cos the table which i am storing these new details has email address as its foreign key and i need to store the same value.
many thanks! :o)
the simplest thing to do is create a bean to hold on to values a user enters and simply have access to them using the <%= bean.getEMAIL() %> or something like that. For multiple form pages, I like using <input type=hidden ...> to store values without having to create object to store them.
But I think in your case, since you have a processing page for the form before it goes on then the bean is the best solution.
Good luck
Similar Messages
-
Maintaining Transactions Across JSP Pages
Hi,
I have a multi page Registration (3 steps). On each step data submitted is taken
to the database via an EJB component (Session Bean). How do I maintain a transaction
across these JSP pages (i.e. either in the EJB or in the jsp) so that the data
in the database is consistent? So if there is a problem in the 3rd step the data
submitted in the first two steps should be rolled back.
Can I use a statefull session beans, which will maintain a database connection
created during the first step, so that I can use the same connection for steps
2 & 3. In the first step after getting the database connection I will begin a
transaction and insert the first part of the data, then this connection will be
maintained by the statefull session and used for steps 2 & 3. At the end I will
commit the transaction. Will this work?
How do I maintain transaction across multiple pages? Is there is any standards
for this scenario where the transaction is maintained across multiple pages. I
cannot carry data across the jsp pages because of the complex data collected.
Any help appreciated.
Regards
-MohanRajYou can not and should not do it the way that you are proposing. Keeping a transaction
open across any interaction with the user is a big mistake. Transactions are scarce
resources. They need to be short. You will need to collect the data from the three
pages in the servlet itself. You can use the HTTPSession, or hidden fields in
the forms. Only after all of the data is collected should you begin a transaction
and update the database. Alternatively, you could store the partial data in a
temporary database table, and move it to a permanent table when all of the data
has been provided. -
Problem in sending drop down list value to jsp page showing null value
i am trying to send a drop down list value from client side to a jsp page but getting null value
this is first page where i have accessed data from database and putted it in a drop down list
<select name="sub">
<%
while(rs2.next())
cat=rs2.getString(1);
%><option value="<%=cat%>"><%=cat%></option><%
}%></select>
<input type="submit" value="Go"></input>
now on submit i am going to another page
where i want the selected value from drop down list to be printed
i have used there
<%
String subject= request.getParameter( "sub.value" );
out.println(subject);
%>
but it is printing null here what is the problem that i m facing
thanx & reagrds
sweetyhow to generate dynamically names for text boxes
i am generating text boxes in while loop when selecting data from database
while(rs1.next())
name=rs1.getString(1);%>
<tr>
<td>1</td>
<td><%out.println(name);
//i am printing here stud_id a unique key and want to update records from following text boxes to particular stud_id
%></td>
<td><input type="text" name="????"></input></td>
<td><input type="text" name="????"></input></td>
<td><input type="text" name="????"></input></td>
<td><input type="text" name="????"></input></td>
</tr><%
the structure is like
stud_id | attended theory | conducted theory | ateended practical | conducted practical
where attended theory, conducted theory............. are to be inputed manually for all students and then update in database
so i am facing problem in generating names for textboxes how to do that
so that those can be updated in database for particular student
Thanx & Regards
sweety -
How to return javascript function value to jsp page
Hi i want to retrieve values from javascript function to jsp page, how can i do that ? i am trying this but its not working
<script language="javascript" type="text/javascript" src="/feedback/common/scripts/config.js"></script>
<script language="javascript" type="text/javascript" src="/feedback/common/scripts/richtext.js"></script>
<td>
<jsp:param id="description" value= "<%=request.initRTE('', '')%>"/>
</td>
here this initRTE function is used for displaying rich text editor .....i want to retrieve back the contetnt written in this editor and save it to DB.
Please help.
Edited by: xtech on Apr 4, 2008 12:00 PMsurely i will do that but my app is still not working.....
here is my code
</td>
<td align="left">
<script language="javascript" type="text/javascript" src="/feedback/common/scripts/config.js"></script>
<script language="javascript" type="text/javascript" src="/feedback/common/scripts/richtext.js"></script>
<h:inputHidden id="introtext" value= "<%=request.getParameterValues(description)%>">
<script>
initRTE('','');
</script>
</td>
in java script function i am geeting the text content
function initRTE(rtePreloadContent, rteCSS) {
rtePreloadContent=document.getElementById('surveyinfo:introtext').value;
startRTE(rtePreloadContent);
menuBuilder();
var description= document.getElementById(rteFormName).value;
return description;
basically i want to get the text written in text editor in jsp and want to send it to DB.(Here initRTE() function is calling rich text editor)
i have downloaded this editor from this url
http://freerichtexteditor.com/page/4.htm
and trying to embed it in my app. -
Help posting correct Array[value] to JSP page
Hello,
Can someone please tell me what is wrong with this? I am posting the following page (only a portion of the page is listed below) to another jsp page. It consists of a listing of books for sale. Next to each book is a separate "add to cart" button. I want to send the corresponding "isbn" (indexed in an Array) to the next page. When I add print stmts for each record, I can see that the correct isbn is attached to each book.
The problem is that when I post this to the next page, the formparm for isbn is always the 1st isbn in the array, instead of the selecgtedIsbn. Why???
Thanks in advance!
<CODE>
<% for(int i=0; i < isbnValues.length; i++) { %>
<TABLE>
<% if ( isbnValues[i] != null) { %>
<tr>
<td> <B><%= titleValues[i] %> </B> </td>
<INPUT TYPE="HIDDEN" NAME="selectedIsbn" VALUE="<%= isbnValues[i] %> "></INPUT>
<INPUT TYPE="HIDDEN" NAME="selectedPrice" VALUE="<%= priceValues[i] %> "></INPUT>
<td align="right"> <i>Price: </i>
<% DecimalFormat df = new DecimalFormat("$#,##0.00");
String strPrice = df.format(Double.parseDouble(priceValues));
%>
<%= strPrice %> <br>
</td>
<td align="right"><i>Quantity:</i>
<INPUT TYPE="TEXT" NAME="qty" VALUE="1"></INPUT> <br> </td>
<td align="right">
<INPUT TYPE="SUBMIT" VALUE="Add to Shopping Cart"></INPUT> <br>
</td>
</tr>
<% } %> <%-- end if isbn --%>
</TABLE>
<% } %> <%-- end for loop --%>
</CODE>Hi,
I have the indexes, but they were somehow removed when I posted the code. I used the wrong tags.
I used the right tag and added spaces around the [" i "].
Let's try again... Here's the code:
<% for(int i=0; i < isbnValues.length; i++) { %>
<TABLE>
<% if ( isbnValues[ i ] != null) { %>
<tr>
<td> <B><%= titleValues[ i ] %> </B> </td>
<INPUT TYPE="HIDDEN" NAME="selectedIsbn" VALUE="<%= isbnValues[ i ] %> "></INPUT>
<INPUT TYPE="HIDDEN" NAME="selectedPrice" VALUE="<%= priceValues[ i ] %> "></INPUT>
<td align="right"> <i>Price: </i>
<% DecimalFormat df = new DecimalFormat("$#,##0.00");
String strPrice = df.format(Double.parseDouble(priceValues[ i ]));
%>
<%= strPrice %> <br>
</td>
<td align="right"><i>Quantity:</i>
<INPUT TYPE="TEXT" NAME="qty" VALUE="1"></INPUT> <br> </td>
<td align="right">
<INPUT TYPE="SUBMIT" VALUE="Add to Shopping Cart"></INPUT> <br>
</td>
</tr>
<% } %> <%-- end if isbn --%>
</TABLE>
<% } %> <%-- end for loop --%> -
Admin1.jsp
In this jsp page i have a drop down list with<select name=Update
From this page i move to the page Adnim2.jsp
Admin2.jsp
In this page i request for the value of selected entry in the drop down list as follows
String a=request.getParameter("Update");
From this page i move onto a servlet UpdateContribution.java
UpdateContribution.java
Here i need the value of the selected entry in drop down list ie Update
but String a=request.getParameter("Update"); does not work here and i get a Null Pointer Exception
Please help meIn Admin2.jsp, add a hidden form field and assign the selected value of drop-down to it. Now, you can obtain
the selected value of drop-down in Servlet(UpdateContribution.java) using given hidden form field.
Or,
Store the selected value of drop-down list in session. Now, you can obtain the value in servlet(UpdateContribution.java) through session -
Update checkbox values in jsp page back to OBPM Process
Dear experts,
I am having a small problem with JSP and I was wondering if anyone could shed some light on it.
My situation is as follows, currently I have
<f:invoke var="${orderDetails}" methodName="getIndicatorsY" retAttName="indicator1"/>
<c:forEach var="indicators1" begin="0" items="${indicator1}" varStatus="status">
<tr>
<td width="27">
<input type="checkbox" name="C1" value="I am a checkbox" checked></td>
<<td><font size="2"><c:out value="${indicators1}"/></font></td>
</tr>
</c:forEach>
What this code does is, if uses the fuego talib and invokes a method in bpm which has a database call and returns an array of string.
Thus on the jsp page, when it is loaded, you will see a table which has 2 columns. 1st column is a checkbox, 2nd column is the information in the string array.
My dilemma is like so, when a user unchecks the box, I need to be able to update bpm and subsequently the database to reflect the change from checked to unchecked.
A question, is it possible to return a bpm object from that invoke rather than just a simple string array?
I have yet to find a way to do it. Could be my lack of experience in JSP :( Any help or sample code is greatly appreciated. Thank you!i think you'll have more chance in this forum :
Java Server Pages (JSP) -
To pass value between jsp page
How can I pass hidden's value from a jsp page to other?
My code is:
a.jsp
<h:form id="insUser">
<h:inputHidden id="flag" value="1"></h:inputHidden>
</h:form>
b.jsp
<%String flag="";
flag=request.getParameter("flag");
out.print("flag="+flag);
%>
b.jsp shows: flag=null
Could you help me?Because this hidden field id is insUser:flag, but not just flag.
If you have subview or other naming container(s) around form, the id name might be even longer.
Sergey : https://ajax4jsf.dev.java.net/ -
Passing values between jsp pages
Hi all,
I am a newbie to jsp. I am trying to pass value from one jsp to another.
Let me post the code here and make my point clear. I have 3 jsp pages and am trying to get the value into my 3rd page that was in the first page.
This is my Test.jsp page:
<%@page contentType="text/html"%>
<html>
<head><title>Test JSP Page</title></head>
<body>
<%-- <jsp:useBean id="beanInstanceName" scope="session" class="package.class" /> --%>
<%-- <jsp:getProperty name="beanInstanceName" property="propertyName" /> --%>
Testing.. JSP Page
<FORM action='Response.jsp' method="POST">
<input type='Text' name='get_name'>
<input type="submit" value="Click Me">
</FORM>
</body>
</html>
This is my response.jsp page:
<%@page contentType="text/html"%>
<%@page import = "sun.jdbc.rowset.CachedRowSet" %>
<html>
<head><title>Response Page</title></head>
<body>
<%-- <jsp:useBean id="beanInstanceName" scope="session" class="package.class" /> --%>
<%-- <jsp:getProperty name="beanInstanceName" property="propertyName" /> --%>
Thank you... <%=request.getParameter("get_name") %>
// I want to pass this get_name to my next page, but since request.getParameter returns an object and not a string, how will I capture the value and pass it to my next page.
</body>
</html>
The 3rd jsp page is:
<%@page contentType="text/html"%>
<html>
<head><title>JSP Page</title></head>
<body>
// I am trying to get the value of the name here in this page.
<%-- <jsp:useBean id="beanInstanceName" scope="session" class="package.class" /> --%>
<%-- <jsp:getProperty name="beanInstanceName" property="propertyName" /> --%>
</body>
</html>
Your help is appreciated.
ThanksHi,
Thanks for the reply, it works. I was wondering whether this is an efficient way of doing this. What I want to do further is to setup a connection to a database and use the value I got from my previous page to query the DB and get the results and display.
I have see some code in the java website and a lot of people do by writting a bean /class(believe bean is just a class) and then importing it and do the things that way. I have good knowledge of OO and Java as a language and would definitely love to do it this way.
What i think i am missing is the basic idea to doing this way. So if you could let me know how to do this using java classes I would really appreciate it. If its too much to explain can u point to some good source(URL's) that explain's this. I have searched on this and all i find is code with no good explaination.
Thanks a lot -
Passing value to jsp page by clicking a hyperlink
I have a hyperlink in a jsp page1. The hyperlink is for another jsp page2. I have a string value in JSP page1, which I want to pass to jsp page2 when user clicks the hyperlink. Can anyone tell me what will be the suitable way to do this? Thanks.
here's the source to two very simple jsps that do what you want..
<HTML>
<HEAD>
<TITLE>
ForwardValue
</TITLE>
</HEAD>
<BODY>
<H1>
Go To GetValue.jsp
</H1>
</BODY>
</HTML>
<HTML>
<HEAD>
<TITLE>
GetValue
</TITLE>
</HEAD>
<BODY>
<H1>
<%= request.getParameter("value") %>
</H1>
</BODY>
</HTML> -
Pass bean property name across JSP pages
First, the sample code:
<%-- ================ some.jsp =============== --%>
<%-- bunch of code [...] --%>
<tr>
<td><bean:message key="prompt.desc" /></td>
<td><html:textarea property="desc" /></td>
</tr>
<tr>
<td>
<bean:message key="prompt.notes" />
<tiles:insert page="checkSpellTile.jsp" flush="false"></tiles:insert>
</td>
</tr>
<tr>
<td><html:textarea property="notes" /></td>
</tr>
<%-- ================ end some.jsp =============== --%>
<%-- ================ checkSpellTile.jsp =============== --%>
<%-- some JSP code [...] --%>
<spellingComp:executeSpelling
mode="popup"
textComponentName="notes"
/>
<%-- ================ end checkSpellTile.jsp =============== --%>
So, my first foray into JSP programming - I have a number of
different JSP pages that need spell check widgets associated
to some text fields. The sample code shown works fine. The
prompt, "Notes ...:" is following by the spell check
[clickable] widget. Then the user clicks the widget, the
spell check is launched and it checks the text in the
"notes" field for the form.
The sticky situation that I can't seem to solve is that each
of the forms associated with each of the different JSP pages
has a different name for the text field (that needs to be
spell checked).
I've tried doing this (between the <tiles:insert...></tiles:insert...>):
<tiles:put name="theNotes" beanName="orderForm" beanProperty="notes"/>
... and then in the checkSpellTile.jsp, inserting this:
<tiles:importAttribute name="theNotes"/>
... and then for the "textComponentName" attribute:
textComponentName="theNotes"
Any ideas how do solve this problem?First, the sample code:
<%-- ================ some.jsp =============== --%>
<%-- bunch of code [...] --%>
<tr>
<td><bean:message key="prompt.desc" /></td>
<td><html:textarea property="desc" /></td>
</tr>
<tr>
<td>
<bean:message key="prompt.notes" />
<tiles:insert page="checkSpellTile.jsp" flush="false"></tiles:insert>
</td>
</tr>
<tr>
<td><html:textarea property="notes" /></td>
</tr>
<%-- ================ end some.jsp =============== --%>
<%-- ================ checkSpellTile.jsp =============== --%>
<%-- some JSP code [...] --%>
<spellingComp:executeSpelling
mode="popup"
textComponentName="notes"
/>
<%-- ================ end checkSpellTile.jsp =============== --%>
So, my first foray into JSP programming - I have a number of
different JSP pages that need spell check widgets associated
to some text fields. The sample code shown works fine. The
prompt, "Notes ...:" is following by the spell check
[clickable] widget. Then the user clicks the widget, the
spell check is launched and it checks the text in the
"notes" field for the form.
The sticky situation that I can't seem to solve is that each
of the forms associated with each of the different JSP pages
has a different name for the text field (that needs to be
spell checked).
I've tried doing this (between the <tiles:insert...></tiles:insert...>):
<tiles:put name="theNotes" beanName="orderForm" beanProperty="notes"/>
... and then in the checkSpellTile.jsp, inserting this:
<tiles:importAttribute name="theNotes"/>
... and then for the "textComponentName" attribute:
textComponentName="theNotes"
Any ideas how do solve this problem? -
Post and Get value in jsp page
I have two pages
1. Occasion.jsp
2. Occasionsdetail.jsp
i select values from database in occasion for example
a
b
c
they become links when i click on one of these links it call Occasiondetail form. Where i want to display details of that particular record
On occasion page i am passing value which is displaying in last of address bar of occasionsdetail page
How can i use that value in occasiondetail form
both files code is pasted
Occasions.jsp
<head>
<title>
Riphah International University
</title>
</head>
<body bgcolor="#ffffff">
<form method="POST" action="occasionDetails.jsp">
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td align="center" bgcolor="#6633FF"> <strong><font color="#000000">Occasions</font></strong> </td>
</tr>
<% org.riu.db.utility.DBHandler dbHandler = new org.riu.db.utility.DBHandler();
if ( dbHandler.getConnection() ) {
org.riu.db.datastructureaccess.OccasionAccess occasionAccess = new org.riu.db.datastructureaccess.OccasionAccess(dbHandler);
java.util.ArrayList occasions = occasionAccess.getOccasions();
if ( occasions == null || occasions.isEmpty() ) { %>
<tr>
<td align="center">
</td>
</tr>
<% } else {
for ( int i = 0; i < occasions.size(); i++ ) {
org.riu.db.datastructure.Occasion occasion = (org.riu.db.datastructure.Occasion) occasions.get(i); %>
<tr>
<td align="center">
<a href="occasionDetails.jsp?OccasionID <%=occasion.getOccasionID() %> "><%= occasion.getName() %></a> <%= " on " + occasion.getDate() %><%= + occasion.getSemesterID()%>
</td>
</tr>
<tr>
<td align="center">
<hr />
</td>
</tr>
<% }
} %>
</table>
<p align="center">Back</p>
</form>
</body>
</html>
OccasionDetail.jsp
<head>
<title>
Riphah International University
</title>
</head>
<body bgcolor="#ffffff">
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td align="center" bgcolor="#6633FF"> <strong><font color="#000000">Occasion Details</font></strong> </td>
</tr>
<% org.riu.db.utility.DBHandler dbHandler = new org.riu.db.utility.DBHandler();
if ( dbHandler.getConnection() ) {
org.riu.db.datastructureaccess.OccasionAccess occasionAccess = new org.riu.db.datastructureaccess.OccasionAccess(dbHandler);
java.util.ArrayList occasions = occasionAccess.getOccasionswhere(I want to use that value here);
// new Integer(request.getParameter("OccasionID")).intValue();
if ( occasions == null || occasions.isEmpty() ) { %>
<tr>
<td align="center">
</td>
</tr>
<% } else {
for ( int i = 0; i < occasions.size(); i++ ) {
org.riu.db.datastructure.Occasion occasion = (org.riu.db.datastructure.Occasion) occasions.get(i);%>
<tr>
<td align="center">
Venue: <%= occasion.getVenue()%>
</td>
</tr>
<tr>
<td align="center">
Time: <%= occasion.getTime() %>
</td>
</tr>
<tr>
<td align="center">
<hr />
</td>
</tr>
<% }
} %>
</table>
<p align="center">Back</p>
</body>
</html>Are your records javascript variables? If so, you can use a json formatter to serialize the records to a string and send it from PageA to PageB using mechanism that supports strings (i.e. query parameter, cookie, etc).
You can learn more about json at http://www.json.org/ and about a json serializer/parser at http://www.json.org/js.html . -
I would like to pass values between pages.
I don't want showing up on the url. Ex: some.jsp?param=value
I don't feel it's safe.
It's not coming from form either....
How can I hide the value and pass it to next page?
I want to pass the value when the user click on a hyperlink
Thanks In Advance.
Message was edited by:
TheepanClient side information is never safe no matter what you do. If the values don't end up in the url, they are always present SOMEWHERE in the html content.
If you don't want the values to end up in the url, rework the page so it DOES do a post form submit. You could turn the hyperlink into a javascript call that submits the form for you. -
Sending value to JSP page from Tag Handler
Is there some reason why a call to setAttribute inside a Body tag handler would not succeed in making visible a variable outside the scope of the tag? I mean a situation like this:
<% String p=request.getParameter("p"); %>
<taglib:tag count="<%= p %>">
...body which handler fills in...
</taglib:tag>
<form action="thispage.jsp?p=<% newcount %>">
<input type=submit>
</form>
Assume that "count" and "newcount" are defined in the Tag Extra Info class for this handler and that TLD allows a run time evaluation of the "count" attribute.
(The idea here is to have the handler recall the same jsp file with an incremented counter.)
Some other way to do this?
Thanks,
AlanNever mind... I see that I forgot to set the scope of the scripting variable to AT_END in the "Handler Extra Info" class.
-
Passing value from JSP to JApplet
Hello,
I am stuck up with a problem, can anyone please tell me how do i pass a value from a JSP page
to a JApplet,
and the parameter passed through JSP should be displaed in the JTextArea.
It would be kindful if any of you could help.
Thanks
Sanamhello,
thanks for reply.
I know how to pass parameters from html,
I want to pass values from jsp page,
and i dono how to do it, may be we cann pass values through url connection but i dono how.
if anone knows plz help me in solving this.
i hvae posted my applet code.
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.JToolBar;
import javax.swing.JButton;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JTextArea;
import javax.swing.JScrollPane;
import javax.swing.JPanel;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.net.*;
import java.sql.*;
<applet code = "DocApplet" width = 500 height =5000>
</applet>
public class DocApplet extends JApplet
private JPanel jp;
private Container cp;
private JTextArea jt;
private JToolBar tb;
private JScrollPane sp;
private String annotation;
private String url;
private Connection con;
private Statement stmt;
public void init()
jp = new JPanel();
cp = getContentPane();
jt = new JTextArea();
tb = new JToolBar();
sp = new JScrollPane(jt);
repaint();
public void start()
jp.setLayout(new BorderLayout());
jp.add(tb, BorderLayout.NORTH);
jp.add(sp, BorderLayout.CENTER);
jt.setBackground(Color.BLACK);
jt.setForeground(Color.WHITE);
setContentPane(jp);
addButtons(tb);
repaint();
public void run()
repaint();
public void paint()
private void addButtons(JToolBar tb)
JButton button = null;
button = new JButton("Save");
button.addActionListener(new ActionListener()
public void actionPerformed(ActionEvent e)
tb.add(button);
}
Maybe you are looking for
-
Photos don't display on book pages after upgrading to 9.4.2
I have several books I created in version 9.4.1. After upgrading to iPhoto 9.4.2, most of the pictures will not display on the book pages. Only 1 photo displays out of 3 or 4 photos on the page. Is there a setting that has changed? Using Mountain Lio
-
Hello Adobe. We have our PDF form and are having issues with everyone being able to submit it from our website. The link is http://qualitystaffingsolution.com/test-pdf/ But after submitting it, one of our programmers can get his to go through on al
-
Hello everyone, I was wondering if you could point me to a sort of "user's guide" or "developer's guide" for Anychart (the component that Apex uses to generate flash charts). The "documentation" I found on their site (http://www.anychart.com/products
-
Searching for orders by Description long text
Team, I am able to search using IW38 and IW37N by Order description short text. Is there a way for me to search the long text descriptions of PM orders?
-
My photoshop elements 11 keeps crashing why?
my photoshop elements keeps crashing iv uninstalled and reinstalled and it still keeps crashng and i need it for my uni work i dont know what to do it wont even let me open work into it without it crashing HELP