Solved

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

Posted on 2003-11-04
6
260 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 3

Accepted Solution

by:
applekanna earned 250 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

Independent Software Vendors: 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!

Question has a verified solution.

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

Configuring Remote Assistance for use with SCCM
How many times a day do you open, acknowledge, or close an IT incident? What’s your process? Do you have a process depending on the incident, systems involved, and other factors? New Relic Alerts gives you options for how you interact with notifica…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

734 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