Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6107359
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:10:48+00:00 2026-05-23T14:10:48+00:00

This is my login page <h:outputText value=ENTER USERNAME ></h:outputText> <p:inputText value=#{treeBean.username} id=user></p:inputText> <h:outputText value=ENTER

  • 0

This is my login page

<h:outputText value="ENTER USERNAME" ></h:outputText>
<p:inputText value="#{treeBean.username}" id="user"></p:inputText>
<h:outputText value="ENTER PASSWORD" ></h:outputText>
<p:inputText value="#{treeBean.userpass}" id="pass"></p:inputText>
<p:commandButton value="GO"  action="#{treeBean.checkuser}" onclick="redirect()"></p:commandButton>
<script type="text/javascript">
function redirect()
{
window.location="/arcpage/arc.jsf";   
}
</script>

this is my treeBean.checkuser function

public void checkuser()
{
Connection con=null;
try
{
Class.forName("com.mysql.jdbc.Driver");
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/", "root", "root");
try
{
st.executeUpdate("USE ARCPAGE");
String update="SELECT * FROM USER WHERE USER_NAME=? AND USER_PASS=?";
    PreparedStatement prest=con.prepareStatement(update);
    prest.setString(1,username);
    prest.setString(2,userpass);
ResultSet rs=prest.executeQuery();
if(rs.next()==false)
{
check="false";
}
else
{
check="true";
}
    }}}

This is My main page:

<script type="text/javascript">
if(check!="true")
{
 window.location="/arcpage/login.jsf";   
}
</script>
<Main Page Content>

If I type the correct username-pass combination I am redirected to the login page instead of the main page. If I enter the correct combination again I am redirected to the main page. Even if I enter a wrong combination the second time I am redirected to the main page. I think the main page is being executed first and then the checkuser() is being executed so the value of check is not updated before the main page is displayed.
Why is this happening?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T14:10:49+00:00Added an answer on May 23, 2026 at 2:10 pm

    That’s because you added some JavaScript function to the onclick which does the redirect. This is invoked when the user clicks the button. This in turn causes the JSF action being completely skipped. You also seem to be thinking that JSF and JavaScript runs in sync somehow. This is untrue. It are two completely distinct languages. JSF runs in webserver only, produces HTML/CSS/JS code and sends it to webbrowser. JS runs in webbrowser and intercepts on HTML DOM tree only.

    To fix the problem, just remove the onclick and do the navigation in JSF action method. So:

    <p:commandButton value="GO"  action="#{treeBean.checkuser}" />
    

    with

    public String checkuser() {
        User user = userService.find(username, password);
    
        if (user == null) {
            return "login";
        } else {
            return "arc";
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Login page that captures User input like this. MD5calc ss =
i have this page . login: fer password: m Note: after login you will
Can anyone see anything wrong with this login script: public function login($username, $pass, $remember)
I'm wondering if I have a web service like this: Login(username, password) or a
This question is related to my other question How to redirect to Login page
I have this situation: There are a login page with a login form (form
I have this login.xhtml JSF page: <?xml version=1.0?> <jsp:root version=2.0 xmlns:jsp=http://java.sun.com/JSP/Page xmlns:f=http://java.sun.com/jsf/core xmlns:h=http://java.sun.com/jsf/html> <jsp:directive.page
I have created this login page. <asp:Label id=Label2 style=Z-INDEX: 103; LEFT: 112px; POSITION: absolute;
I'm loading a simple page using: $.get('../admin/login.php', function(data) { $('#box-contents').html(data); }); Now, on this
I'm Newbie in cakephp and I create register page and login page this problem

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.