Solved

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

Posted on 2003-11-04
6
256 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 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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
xjc and jaxb 2 89
nested if has else if 13 88
Market Place not working in Eclipse Luna 2 84
withoutString  challenge 40 149
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
For cloud, the “train has left the station” and in the Microsoft ERP & CRM world, that means the next generation of enterprise software from Microsoft is here: Dynamics 365 is Microsoft’s new integrated business solution that unifies CRM and ERP fun…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

760 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

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now