Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Sending a user back a page in history from a form submission

Posted on 2003-11-04
6
Medium Priority
?
263 Views
Last Modified: 2010-04-01
I have a jsp page that submits a form back to itself. When the page is submitted it checks a value for duplicates in the database. If a record is found It alerts the user and this is where the problem occurs.
I want it to take the user back to the page in the state it was when they entered the data but it submits the form data and moves onto the next process.
I have tried history.back() and window.go()
as well as
parent.frames['header'].history.back();parent.frames['main'].history.back();
(the site unfortunately uses framesets at the moment)

below is a snippet of the surrounding code. If anyone could advise me what I'm doing wrong<!--as my javascript knowledge is extremely noobish :| --> I'd be extremely grateful

cheers in advance


//get email submitted and test to make sure it is unique record
<%
  try {
     email = request.getParameter("email");
  }
  catch(Exception e) {
     throw new Exception("email not passed in queyystring");
  }  
try {
     query = "begin ? := \"CHANGEDB_REP\".\"CHECKIFEMAILEXISTS\"(?); end;";

     try{
       connection.setAutoCommit(false);
         try {
            stmt =(OracleCallableStatement)connection.prepareCall(query);
            str = new  oracle.sql.CHAR(email ,myCharSet);
            stmt.setCHAR(2, str);
            stmt.registerOutParameter(1, OracleTypes.NUMBER);
            stmt.execute();
            connection.commit();

            try {
               output = stmt.getNUMBER(1);

               if (output.intValue() > 0) {
%>
                  <script language="Javascript">
                      alert('Sorry the system already has a user registered with the
                              email address <%=email%>');
                      window.history.go(-2);
                  </script>
<%
               }
            }
            catch (Exception e) {
               e.printStackTrace();
            }
            stmt.close();
         }
         catch (Exception e) {
             System.err.println("error creating statement for checkifemailexists");
             e.printStackTrace();
         }
     }
     catch(Exception e) {
        e.printStackTrace();
     }
 }
%>
0
Comment
Question by:RapidDrinker
  • 3
  • 2
6 Comments
 
LVL 3

Accepted Solution

by:
applekanna earned 750 total points
ID: 9683978
We can do this witithout JS

add another parameter in the JSP page whcih lets you know if it is a first request or not say

<input type = hidden name = "error" value =""> for the first time when the page is viewed itself whcih means the user enters data and

suppose this is the signup page

<%
  try {
     email = request.getParameter("email");
     error = request.getParameter("error");

  }
  catch(Exception e) {
     throw new Exception("email not passed in queyystring");

if(error.equals(true)) //duplicate login
{
 //add code to display that you have an error
}
else if (error.equals(false))
{
  //add code to submit the form or use a bean to submit data to db
}
else if(error == null) //first time it is being submitted so get to the db and chec it
{
....

   try {
               output = stmt.getNUMBER(1);

               if (output.intValue() > 0) {
                //error so do
               response.sendRedirect(yourPage?error=true&email=jhjh@hkj.cm);
               }
              else
               response.sendRedirect(yourPage?error=false&email=jhjh@hkj.cm)




}
 

Hope this helps.
If code is still not clear and you want to continue mail again I will explain
  }  
0
 
LVL 14

Expert Comment

by:kennethxu
ID: 9684347
shouldn't it be history.go(-1)?
0
 
LVL 3

Expert Comment

by:applekanna
ID: 9684467
expert kennethxu

RFC on my approach :)
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 14

Expert Comment

by:kennethxu
ID: 9689616
>> RFC on my approach :)
I think the question is about duplicate registration instead of duplicate login. Asker want to push user back to the registration page and correct the email address, then submit again.

There are usually 2 approaches. one is what asker did, use javascript the send user back. another is to redisplay the login page with all the data pre-polulated with what user has already submitted.
0
 
LVL 14

Expert Comment

by:kennethxu
ID: 9689622
sorry, I meant to redisplay the "registration" page with ...
0
 

Author Comment

by:RapidDrinker
ID: 9689964
Hi thanks all,

I kinda got it sorted myself before all your kind help. I simply added a flag in the after the test for duplication which determined whether or not the serverside code was executed or not. lol I still got to get my head around the whole client side scripting. I've accepted apples reply as it was along the same idea as what I used.

thanx for ya help
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Did you know there are services out there that can turn an Instagram feed into an RSS feed? I found some interesting exclusive Instagram content which I wanted to follow without signing up for yet another social media account. RSS to the rescue!
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…

876 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question