Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 9 of 9

Thread: Unnable to make validations work for login screen

  1. #1
    Junior Member
    Join Date
    Jul 2010
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation Unnable to make validations work for login screen

    Hi All

    I am breaking my head for a long time. Everything seems to be fine but I am not able to apply validation framework to my login screen. Everything seems to be fine but still validation is not working. Currently what i am trying to achieve, is to throw error message when the user doesnt enter the username in the login screen.

    The attached zip file contains the entire code i have developed but cant figure out what mistake i have made. Even though i don't enter the user name in the login screen the action gets executed and error message is not displayed. It would be really great if someone could identify what mistake i have made in the code.

    Fierof2
    Attached Files Attached Files


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,145
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Unnable to make validations work for login screen

    Its a hugh bunch of code for anyone to search thru. Can you reduce your problem to a small program that would compile and execute and demo the problem? Remove all the code that is not part of the problem.
    Have you tried debugging it by adding println() statements to show how variables change and where execution flow goes?

  3. #3
    Junior Member
    Join Date
    Jul 2010
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Unnable to make validations work for login screen

    Hi Norm

    I have attached the new zip file that contains only the login page info. All the unwanted files are removed from this.

    Rahul
    Attached Files Attached Files

  4. #4
    Junior Member
    Join Date
    Jul 2010
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Unnable to make validations work for login screen

    Below is the content of login.jsp file
    -----------------------------------------
    HTML Code:
    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
        pageEncoding="ISO-8859-1" errorPage="error.jsp"%>
    <%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
    <%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
    <!doctype html>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>Repository</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <script type="text/javascript" src="js/shadedborder.js"></script>
    <script type="text/javascript" src="js/ajax.js"> </script>
    <link href="css/style.css" rel="stylesheet" type="text/css">
    </head>
    <body>
    <html:form action="/login" method="POST">
    
    <div id="content">
      <div id="innerholder">
        <h3><span></span></h3>
            	<div>
                	<div id="usernamelbl"><b><bean:message bundle="html" key="label.login.username"/> :</b></div>
                    <div class="roundedfield" >
                    	<html:text property="username" styleId="username"/>  
                    </div>
                </div>
                <div>
                    <div id="passwordlbl"><b><bean:message bundle="html" key="label.login.password"/> :</b></div>
                    <div class="roundedfield" >
                    <html:password property="password" styleId="password"/>
                    </div>    
                </div>
                <div>
                    <div id="projectlbl"><b><bean:message bundle="html" key="label.login.project"/> :</b></div>
                    <div class="nonroundedfield">
                    <html:select property="project"><html:option value=""></html:option></html:select> 
                    </div>    
                </div>
                <br />
                <html:button property="authenticatebutton" onclick="authenticate();" styleId="authenticatebutton">
                <bean:message bundle="html" key="btn.login.authenticate"/></html:button> 
                <html:submit property="loginbutton" styleId="loginbutton">
                <bean:message bundle="html" key="btn.login.login"/></html:submit> 
      </div>
    </div>
    </html:form>
    <font color="red">
    <html:errors/>
    </font>
    <script language="javascript" type="text/javascript">  
        holderBorder.render('content');
    </script>
    </body>
    </html>
    below is the content of Struts-config file

    -----------------------------------------
    <!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.3//EN" "http://struts.apache.org/dtds/struts-config_1_3.dtd">
    <struts-config>
     
     
    <!-- ================================================ Form Bean Definitions -->
     
        <form-beans>
    	<form-bean 
    		name="loginForm"
    		type="com.attragroup.tcr.forms.LoginForm" />
        </form-beans>
     
     
    <!-- ========================================= Global Exception Definitions -->
     
        <global-exceptions>
            <!-- sample exception handler
            <exception
                key="expired.password"
                type="app.ExpiredPasswordException"
                path="/changePassword.jsp"/>
            end sample -->
        </global-exceptions>
     
     
    <!-- =========================================== Global Forward Definitions -->
     
        <global-forwards>
            <!-- Default forward to "Welcome" action -->
            <!-- Demonstrates using index.jsp to forward -->
            <forward name="login" path="/login.jsp" />
        </global-forwards>
     
     
    <!-- =========================================== Action Mapping Definitions -->
     
        <action-mappings>
                <!-- Default "Welcome" action -->
                <!-- Forwards to Welcome.jsp -->
            <action path="/login" type="com.attragroup.tcr.action.LoginAction" name="loginForm" scope="request" input="/login.jsp" unknown="true" />
            <action path="/authenticate" type="com.attragroup.tcr.action.AuthenticateProjectAction" />
            <action path="/Welcome" forward="/pages/Welcome.jsp" />
     
     
        </action-mappings>
     
     
    <!-- ======================================== Message Resources Definitions -->
     
        <message-resources parameter="com.attragroup.tcr.settings.MessageResources" key="html" />
        <message-resources parameter="com.attragroup.tcr.settings.ErrorResources"  key="error" />
     
     
    <!-- =============================================== Plug Ins Configuration -->
     
     
      <!-- =================================================== Validator plugin -->
     
        <plug-in className="org.apache.struts.validator.ValidatorPlugIn">
            <set-property property="pathnames" value="/org/apache/struts/validator/validator-rules.xml,
               /WEB-INF/validation.xml" />
        </plug-in>
     
    </struts-config>

    Below is the content of validations.xml

    <?xml version="1.0" encoding="ISO-8859-1" ?>
     
    <!DOCTYPE form-validation PUBLIC
         "-//Apache Software Foundation//DTD Commons Validator Rules Configuration 1.3.0//EN"
         "http://jakarta.apache.org/commons/dtds/validator_1_3_0.dtd">
     
    <form-validation>
     
    <!--
         This is a minimal Validator form file with a couple of examples.
    -->
     
        <global>
     
     
        </global>
     
        <formset>
     
            <!-- An example form -->
            <form name="loginForm">
                <field
                    property="username"
                    depends="required">
                     <arg position="0" bundle="error" key="error.required"/>
                    <!-- <msg name="required" bundle="error" key="loginForm.username"></msg>
                    <msg name="minLength" bundle="error" key="loginForm.username.minlength"></msg>
                    <arg name="minLength" key="${var:minlength}" position="0" resource="false" />
                    <var>
    					<var-name>minlength</var-name>
    					<var-value>5</var-value>
    				</var>  -->
     
                </field>
            </form>
     
        </formset>
     
     
     
    </form-validation>

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,145
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Unnable to make validations work for login screen

    Sorry, I don't have a server with jsp etc.

  6. #6
    Junior Member
    Join Date
    Jul 2010
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Unnable to make validations work for login screen

    what do you mean. Do you mean to say the attachment doesnt contain jsp ?

  7. #7
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,145
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Unnable to make validations work for login screen

    Sorry, I'm not able to make any use of your zip file. It's way to big and complicated and requires many resources that I don't have.
    I was looking for a single file (less than 800 lines) with one or more classes that would compile and execute and demo the problem.

    You need to use some debug techniques to trace thru the logic and find out what is wrong.

  8. #8
    Junior Member
    Join Date
    Jul 2010
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Unnable to make validations work for login screen

    Hi Norm

    I thank you very much for your sincere efforts put so far to help me.

    The newly attached zip file contains only 3 simple java files

    The zip file has only 3 java files

    LoginAction
    LoginForm
    Contants.java

    and only 2 jsp files

    login.jsp
    error.jsp file

    struts files are also present

    others files are js,css, and images which you dont have to worry about.

    I think if you take a look the below files

    1.login.jsp
    2.LoginForm.java
    3.LoginAction.java
    4.struts-config.xml
    5.validation.xml

    You should be able to identify the issue by looking the above files alone.

    If you need any other assistance please dont hesitate to contact me, i will definitely help you in that.

  9. #9
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,145
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Unnable to make validations work for login screen

    Sorry, I don't have the environment to test any code other than what is in .java file that can be compiled and executed.
    Nothing for .jsp files or struts.

Similar Threads

  1. Need help in login page in struts
    By vinothkumarrvk in forum Web Frameworks
    Replies: 4
    Last Post: October 4th, 2011, 02:10 PM
  2. login to website as user, no browser
    By chopficaro in forum Java Theory & Questions
    Replies: 6
    Last Post: May 27th, 2010, 06:55 PM
  3. Http post to login to forum
    By durenir in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 14th, 2010, 11:03 AM
  4. Login form on webpage
    By rosebabz in forum JDBC & Databases
    Replies: 0
    Last Post: January 14th, 2010, 10:34 AM
  5. simple login web service
    By mr_aliagha in forum JavaServer Pages: JSP & JSTL
    Replies: 3
    Last Post: January 5th, 2010, 03:49 PM