/    Sign up×
Community /Pin to ProfileBookmark

Reloading the current Page with IF statement

I can’t seem to figure it out i have this code which i took from a button for reloading a page

[CODE]window.location.reload()[/CODE]

But i cant seem to incorporate it within my Login Script’s IF statement.

[CODE]<%

Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver”).newInstance();

Connection conn = DriverManager.getConnection(“jdbc:odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=C:/Program Files/Apache Software Foundation/Tomcat 6.0/webapps/2009-sem2/cs205189/Final/javaDatabase.accdb;”);

Statement statement = conn.createStatement();

String usernameParam = request.getParameter(“usernameField”);
String passwordParam = request.getParameter(“passwordField”);

ResultSet columns = statement.executeQuery(“SELECT * FROM Users WHERE Username='” +
usernameParam + “‘ AND Pass='” + passwordParam + “‘;”);

String sUserName=null;
String sUserPassword;
if(columns.next())
{
sUserName = columns.getString(“Username”);
sUserPassword = columns.getString(“Pass”);
}

%>

<% if (sUserName != null) {
session.setAttribute(“Successful login”,sUserName); %>
<h3> Your login has succeeded </h3>
<% out.print(sUserName); %>

<% } else { %>

<h3> Login Failed </h3>
window.location.reload()

<% } %>[/CODE]

Basically ive done it so if you type the wrong info it says login failed, yet after that i want it to reload the Login Page.
Any help greatly Appreciated ?

Liam

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@ZeroKilledMar 17.2009 — i'm not familiar with asp (or java). however, the statement need proper script tag. otherwise the statement are just rendered as document's content:
<i>
</i>&lt;&amp;#37; } else { %&gt;

&lt;h3&gt; Login Failed &lt;/h3&gt;
&lt;script type='text/javascript'&gt;window.location.reload();&lt;/script&gt;

&lt;% } %&gt;
Copy linkTweet thisAlerts:
@dntelauthorMar 17.2009 — It is actually Javascript thats what im doing it in ?

Although when i put what u suggested, it flies through normally gets to that part then constantly reloads and locks out of internet explorer :/

kinda need it reloading once lol, but thanks for the try, better than i could do ?
Copy linkTweet thisAlerts:
@rpgfan3233Mar 17.2009 — Well, you never specified the condition for the page to reload. All that you do is that if the username entry is null, the page reloads automatically. You need something that distinguishes between the form having already submitted and the username field being null vs. the form when it hasn't been submitted yet. I'm honestly not sure how you'd do this since I only work with client-side JS, but one idea might be to use the URL to your advantage. You might submit to a URL with "?formSubmitted=1" at the end. Additionally, if the login fails, you'll need to reload the page WITHOUT that at the end, so that a new entry can be made. In that case though, you wouldn't want to reload(); you would want to navigate to a different URL by setting window.location.href to the necessary URL. Just a thought...
Copy linkTweet thisAlerts:
@animalj7Mar 17.2009 — You could use JSP to redirect on an unsuccessful login. It would be something like whats described in the link below.

[URL="http://www.jguru.com/faq/view.jsp?EID=376"]

http://www.jguru.com/faq/view.jsp?EID=376[/URL]


Assuming you don't know enough to pass parameters between JSP pages to alert your login page that there was a successful login (to show a customized message on the page) you could always create another login page with the Login Failed message that has the same logic as your existing page and redirect to that.
×

Success!

Help @dntel spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...