Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2003-11-04
6
Medium Priority
?
262 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 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
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.

 
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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

If you are a mobile app developer and especially develop hybrid mobile apps then these 4 mistakes you must avoid for hybrid app development to be the more genuine app developer.
On September 18, Experts Exchange launched the first installment of the Help Bell, a new feature for Premium Members, Team Accounts, and Qualified Experts. The Help Bell will serve as an additional tool to help teams increase question visibility.
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

715 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