Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Struts In Struts2 login validation, when we submitt the form without input then it shows error but when we again submit it then it doesnt call setter and then it hang out also.

Have Programming Question? Ask it here!
 
 
 


Rahul Shivhare
In Struts2 login validation, when we submitt the form without input then it shows error but when we again submit it then it doesnt call setter and then it hang out also.
1 Answer(s)      a year and 10 months ago
Posted in : Struts


**struts.xml**

<?xml version= 1.0  encoding= UTF-8  ?>

<!DOCTYPE struts PUBLIC
     -//Apache Software Foundation//DTD Struts Configuration 2.0//EN 
     http://struts.apache.org/dtds/struts-2.0.dtd >

<struts>
    <constant name= struts.enable.DynamicMethodInvocation  value= false  />
    <constant name= struts.devMode  value= false  />
    <constant name= struts.convention.result.path  value= /pages  />
    <constant name= struts.convention.action.packages  value= com.icici.recon  />
    <constant name= struts.custom.i18n.resources  value= global  />

    <package name= default  extends= struts-default, json-default  namespace= / >
        <action name= index  class= com.credentek.recon.sms.action.IndexAction >
            <result>/pages/index.jsp</result>
        </action>

        <action name= indexLogin  class= com.credentek.recon.sms.action.IndexAction  method= login >
            <result>/pages/sms/login.jsp</result>
        </action>

        <action name= login  class= com.credentek.recon.sms.action.LoginAction >
            <result >/pages/sms/login.jsp</result>
        </action>

        <action name= showmenu  class= com.credentek.recon.sms.action.LoginAction  method= showmenu >
            <result name= success >pages/menu/menu.jsp</result>
            <result name= error >pages/menu/blank1.jsp</result>
        </action>

    </package>
</struts>



**LoginAction.java**

package com.credentek.recon.sms.action;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.interceptor.SessionAware;
import com.credentek.recon.sms.dao.LoginDAO;
import com.credentek.recon.sms.dao.LoginDAOImpl;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class LoginAction extends ActionSupport implements SessionAware {

    private static final long serialVersionUID = -8841529855335717596L;

    private final Logger log = Logger.getLogger(LoginAction.class);

    private Map<String, Object> session;
    private String userID;

    private String welcomeDetails;
    private String loginDetails;

    private boolean implementationStatus;

    private String subSystem;


    private LoginDAOImpl loginDAO = new LoginDAOImpl();


    public String execute() {

        log.info( Loading login page... );

        log.info( Login page loaded successfully. );

        return SUCCESS;
    }

    public String showmenu() {

        log.info( showmenu  );
System.out.println( show menu.... );
        if(userID.equalsIgnoreCase(  ) || userID == null){
            System.out.println( no user ID..... );
            return ERROR;
        }
        System.out.println( USER ID..... );
        HttpServletRequest request = (HttpServletRequest) ActionContext
        .getContext().get(ServletActionContext.HTTP_REQUEST); 

        log.info( Validating login information... );

        String dateFormat = loginDAO.getDateFormat();
        if(!  .equals(dateFormat)) {
            session.put( dateFormat , dateFormat);
            log.info( Date Format set to   + dateFormat);
        } else {
            session.put( dateFormat ,  dd/MM/yyyy );
            log.error( Date Format is not set properly, please set dateFormat parameter in Parameter table );
        }

        SimpleDateFormat sdf = new SimpleDateFormat(dateFormat); 

        String businessDate =  sdf.format(new Date());

        session.put( userID , userID);
        session.put( userName , userID); 
        session.put( businessDate ,  30/04/2012 );
        session.put( subSystem , subSystem);
        String moduleID = loginDAO.getModuleDetails(subSystem);

        log.info( moduleID is set to   + moduleID );    

        session.put( moduleID , moduleID);

        session.put( lastLoginDate ,    );
        session.put( lastBusinessDate ,    );
        session.put( currencyFormat ,    );

        dateFormat = dateFormat.replace( yy ,  y );
        dateFormat = dateFormat.replace( E ,  D );
        dateFormat = dateFormat.replace( DD ,  D );
        if(StringUtils.countMatches(dateFormat,  MMMM ) == 1)
            dateFormat = dateFormat.replace( MMMM ,  MM );
        else if(StringUtils.countMatches(dateFormat,  MMM ) == 1)
            dateFormat = dateFormat.replace( MMM ,  M );
        else if(StringUtils.countMatches(dateFormat,  MM ) == 1)
            dateFormat = dateFormat.replace( MM ,  mm );
        else if(StringUtils.countMatches(dateFormat,  M ) == 1)
            dateFormat = dateFormat.replace( M ,  m );

        session.put( datePickerFormat , dateFormat);
        log.info( DatePicker format set to   + dateFormat); 

        log.info( Login successfull. Login Information =   + session);

        welcomeDetails =  Welcome   + userID;

        sdf = new SimpleDateFormat( dd MMMM, yyyy HH:mm:ss z );
        loginDetails =  Current Login :   + sdf.format(new Date());

        log.info( Login Details: User-   + userID +  ,   + loginDetails);

        implementationStatus = true;

        request.getSession().setMaxInactiveInterval(60 * 60); 

        return SUCCESS;
    }

    public void setSession(Map<String, Object> session) {
        this.session = session;
    }

    public String getUserID() {
        return userID;
    }

    public void setUserID(String userID) {
        this.userID = userID;
    }

    public String getWelcomeDetails() {
        return welcomeDetails;
    }

    public void setWelcomeDetails(String welcomeDetails) {
        this.welcomeDetails = welcomeDetails;
    }

    public String getLoginDetails() {
        return loginDetails;
    }

    public void setLoginDetails(String loginDetails) {
        this.loginDetails = loginDetails;
    }

    public boolean isImplementationStatus() {
        return implementationStatus;
    }

    public void setImplementationStatus(boolean implementationStatus) {
        this.implementationStatus = implementationStatus;
    }

    public String getSubSystem() {
        return subSystem;
    }

    public void setSubSystem(String subSystem) {
        this.subSystem = subSystem;
    }

}



**index.jsp**

<%@ page language= java  contentType= text/html; charset=ISO-8859-1 
   pageEncoding= ISO-8859-1 %>

<%@ taglib prefix= s  uri= /struts-tags %>
<%@ taglib prefix= sj  uri= /struts-jquery-tags %>

<!DOCTYPE html PUBLIC  -//W3C//DTD HTML 4.01 Transitional//EN   http://www.w3.org/TR/html4/loose.dtd >

<html>
<head>

    <meta http-equiv= Content-Type  content= text/html; charset=utf-8  />
    <meta http-equiv= Content-Style-Type  content= text/css  />
    <meta http-equiv= pragma  content= no-cache  />
    <meta http-equiv= cache-control  content= no-cache  />
    <meta http-equiv= expires  content= 0  />
    <meta http-equiv= keywords  content= struts2, jquery, jquery-ui, plugin, showcase, jqgrid  />
    <meta http-equiv= description  content= Debit Card Reconciliation System  />

    <link href= styles/layout.css  rel= stylesheet  type= text/css  />

    <link rel= stylesheet  href= styles/styles.css  type= text/css  />  

    <!--[if lte IE 7]>
        <link href= styles/patch_layout.css  rel= stylesheet  type= text/css  />
    <![endif]-->

    <!-- This files are needed for AJAX Validation of XHTML Forms -->
    <script type= text/javascript  src= ${pageContext.request.contextPath}/struts/utils.js ></script>
    <script type= text/javascript  src= ${pageContext.request.contextPath}/struts/xhtml/validation.js ></script>

    <script type= text/javascript  src= js/jquery.js ></script>

    <sj:head debug= true  compressed= false  jquerytheme= humanity  loadFromGoogle= false  ajaxhistory= false  defaultIndicator= myDefaultIndicator  defaultLoadingText= Please wait ... />

    <!-- This file includes necessary functions/topics for validation and all topic examples -->
    <script type= text/javascript  src= js/showcase.js ></script>
    <script type= text/javascript  src= js/common.js ></script>
    <script type= text/javascript  src= js/right.js ></script>
    <script type= text/javascript  src= js/date.js ></script>

    <script type= text/javascript  src= js/ui/jquery.ui.datepicker.js ></script>
    <script type= text/javascript  src= js/jquery.tablesorter.js ></script>
    <script type= text/javascript  src= js/jquery.tablesorter.pager.js ></script>
    <script type= text/javascript  src= js/jquery.tablesorter.filter.js ></script>
    <script type= text/javascript  src= js/ui/jquery.ui.core.js ></script>
    <script type= text/javascript  src= js/ui/jquery.ui.widget.js ></script>
    <script type= text/javascript  src= js/ui/jquery.ui.mouse.js ></script>
</head>

<body>
    <div class= page_margins >
        <div class= page >
            <table width= 100%  border= 0  class= ui-widget-header >
            <tr>
                <td width= 40% ><div id= headline >
                    <h1 class= ui-state-default  style= background: none; border: none; >Login Attempt </h1>
                    <h4 class= ui-state-default  style= background: none; border: none; >Login  <i><small>Login</small></i></h4>
                    <img id= myDefaultIndicator  src= images/ajax-loader.gif  alt= Loading...  style= display:none />
                </div></td>
                <td width= 30% ><div id= subSystemInfo  class= ui-state-default  style= background: none; border: none;font-size: 20px; ></div> </td>

                <td width= 30% >
            <div >
                <div style= float: right; >                 
                    <s:form id= themeform  action= setlocale  theme= simple >
                        <div id= languageBox >
                            <span>

                            </span>
                            <span>

                            </span>
                        </div>
                        <sj:submit id= submitForm  formIds= themeform  listenTopics= formTopic  cssStyle= display: none;  />

                    </s:form>

                    <div class= ui-state-default  style= background: none; border: none; padding-top: 3px; padding-bottom: 3px; float: right; ><span id= userInfo ></span><span><a id= logout  href= index.action ></a></span></div><br>

                    <div id= loginInfo  class= ui-state-default  style= background: none; border: none;float: right; ></div>

                </div>



            </div>
            </td>
            </tr>
            </table>

            <div id= menu ></div>

            <s:url id= urlLogin  action= login  />
            <sj:div id= main  href= %{urlLogin}  cssStyle= height:320px >
                <img id= indicator  src= images/indicator.gif  alt= Loading...  />
            </sj:div>

            <!-- begin: #footer -->
            <div id= footer >
                Copyright  2012, CredenTek Software & Consultancy Private Limited. <a href= http://www.credentek.com/  target= _blank >www.credentek.com</a>
            </div>
        </div>
    </div>

    <div class= curtain  id= loading-filter  style= display:none; height: 850px; >
        <div style= margin-top: 200px; text-align: center; >  
            <img src= images/loading.gif  width= 110  height= 90  alt= loading ... />
        </div>
    </div>
</body>
</html>



**login.jsp**

<%@ taglib prefix= s  uri= /struts-tags %>
<%@ taglib prefix= sj  uri= /struts-jquery-tags %>

<div id= col3  align= center  style= width: 100%; >
    <div id= col3_content  align= center  class= clearfix  style= width: 90%; >
        <s:url id= urlShowMenu  action= showmenu />
        <%-- <sj:a id= loginLink >Login</sj:a> --%>

        <table cellpadding= 0  cellspacing= 7   border= 0  width= 100% >
            <tr valign= top >
                <td width= 35% ><img src= images/icicibank.jpg  width= 250px ></td>
                <td><br></br><br></br><br></br></td>
                <td  width= 35%  align= right >
                </td>
            </tr>
            <tr>
                <td>
                </td>
                <td>
                    <h4 class= ui-state-default  style= background: none; border: none; >Login</h4>
                </td>
                <td>
                </td>
            </tr>

            <tr>
                <td></td>
                <td>
                <hr></hr>
                </td>
                <td></td>
            </tr>

            <tr>
                <td></td>
                <td>
                    <s:form id= loginForm  theme= simple >
                    <table cellpadding= 0  cellspacing= 15  border= 3  width= 100%  >


                        <tr style= border:0px; >
                            <td width= 50%  style= border:0px;  align= left >User Name </td>
                            <td width= 50%  style= border:0px; >
                                <s:textfield id= userID  cssClass= searchInputText  name= userID ></s:textfield>
                            </td>
                        </tr>
                        <tr style= border:0px; >
                            <td style= border:0px;  align= left >Password </td>
                            <td style= border:0px; ><s:password id= password  cssClass= searchInputText  /></td>
                        </tr>
                        <tr style= border:0px; >
                            <td style= border:0px;  align= left >Sub-System</td>
                            <td style= border:0px; ><s:select name= subSystem  list= { Nostro , CMS }  cssStyle= width:132px  cssClass= searchInputText /></td>
                        </tr>

                        <tr align= right  style= border:0px; >
                            <td align= right  colspan= 2  style= border:0px; >
                                <sj:submit id= loginBtn  name= Logn  href= %{urlShowMenu}  targets= menu  button= true ></sj:submit>    

                            </td>
                        </tr>
                    </table>

                    </s:form>
                </td>
                <td></td>
            </tr>
    </table>

    </div>

    <!-- IE Column Clearing -->
    <div id= ie_clearing ></div>
</div>

<script type= text/javascript >

    $(document).ready(function() {

        $( #bankName ).focus();

        $( #loginBtn ).click(function()
        {
            $( #main ).empty();
        });

    });

</script>

Advertisement
View Answers

Related Tutorials/Questions & Answers:
Struts Login Validation. In This code setter of login page is called only one time again it doesnt call it. Why..?
Struts Login Validation. In This code setter of login page is called only one time again it doesnt call it. Why..?  **struts.xml** <?xml version...="com.credentek.recon.sms.action.IndexAction" method="login"> <
How can we submit a form without a submit button?
How can we submit a form without a submit button?  How can we submit a form without a submit button
Advertisements
when will we get JasperException and parseException?
when will we get JasperException and parseException?  when will we get JasperException and parseException
insertin form data into databse and blank all form field when click on submit button
insertin form data into databse and blank all form field when click on submit... database when click on submit button and blank all form field after inserting...;</td></tr> <tr><td><input type="submit" value="Submit
why should we over ride hashCode(), when equals was over ride()?
why should we over ride hashCode(), when equals was over ride()?  why should we over ride hashCode(), when equals was over ride
Problem In applet Its run on browser but hang and blinking when image is draging some where.
Problem In applet Its run on browser but hang and blinking when image... cards on applet, and also nothing is displaying when I do other work on the same.... In my applet 52 card images is draw and drage and move on the applet, but when I am
when do we get null pointer exception in java
when do we get null pointer exception in java  can anybody explain me abt null pointer exception? like in wt situation do v get NPE? Are these 2 strings same? String str; String str=null
Display set of names in array when we press the first letter
Display set of names in array when we press the first letter  Please help to write a program which have to display set of names in the array when we click the starting letter (like in gmail if we press the letter it will show
Example of login form validation in struts2.2.1framework.
Example of login form validation in struts2.2.1 framework. In this example, we will introduce you to about the login form validation in struts2.2.1 framework. Our login form validation example does not validate the user against
display a list of names(when we press first letter)
display a list of names(when we press first letter)  If i gave...","Zimbabwe"}; Scanner input=new Scanner(System.in); System.out.print..."}; Scanner input=new Scanner(System.in); System.out.print("Enter letter
doesnt run again - Java Beginners
doesnt run again  the code u sent doesnt run and the error msg says... error for the next line just like i have to start a new main code so plz tell the soltion   Hi I am sending u again the code, this code run in my
JSP Login Form with MySQL Database Connection and back end validation
Here we have created a simple login form using MySQL Database Connection and back end validation. We have also added a video tutorial of the program... database and matched with the input value given through the login form. Example
When i click on Monitor Tomcat, it shows
When i click on Monitor Tomcat, it shows   To run servlet i have seen... installed java 7 and tomcat 7, when i click on Monitor Tomcat it shows Application System Error , Access is denied ,Unable to open the service 'Tomcat 7
When i click on Monitor Tomcat, it shows
When i click on Monitor Tomcat, it shows   To run servlet i have seen... installed java 7 and tomcat 7, when i click on Monitor Tomcat it shows Application System Error , Access is denied ,Unable to open the service 'Tomcat 7
login form validation - JSP-Servlet
login form validation  hi, how to validate the login form that contains user name and password using post method . the validation should not allow user to login in the address bar thanks regards, anand
jQuery 'select' form event
jQuery 'select' form event In this tutorial, we will discuss about 'select ' form event to display message when we select something inside input box. In this Example, two input text box are given , when we select
submit a form
submit a form  How can we submit a form without a submit button
Submit comments in database when user clicks on submit button
; message on the page.. If found any error to submit data in database shows... Submit comments in database when user clicks on submit button... database when user clicks the submit button of the page. Create a database: First
struts2 how can we add an radio button to form using a class(doa)
struts2 how can we add an radio button to form using a class(doa)  Hi... button on the registration form how to do plz help me out here is my code model...) { this.documentHistories = documentHistories; } } And my form is : <table width
struts2 how can we add an radio button to form using a class(doa)
struts2 how can we add an radio button to form using a class(doa)  Hi... button on the registration form how to do plz help me out here is my code model...) { this.documentHistories = documentHistories; } } And my form is : <table width
jQuery 'submit' form event
jQuery 'submit' form event In this tutorial, we will discuss about the  'submit' form event of jQuery. In this example , In this example a text box and a button is given, when we hit the button, it will check
display current time when using datetimepiker in struts2
display current time when using datetimepiker in struts2  how to display current time when using datetimepiker in struts2 I set displayFormat="dd/MM.... But it seems, it also doesn't work. Here is my code : public String execute
when refreshing the page the data is stored in data base again
when refreshing the page the data is stored in data base again  Hi, In my application, I am adding form data in database on click of submit button.But the problem is, when user refreshes the page, the data added one more time
What happen when we write static public void instead of public static void?
What happen when we write static public void instead of public static void?  Hi, What happen when we write static public void instead of public static void? Thanks   Hi, The program will compile first then run
Action Submit Html
;  Action Submit in Html is used to submit a form, When a user clicks on a submit button, the form is sent to the specific address... Illustrates an example from Action Submit Html.In this tutorial, we explain you
How to save form fields into the MySql Database without submit button in jsp?
How to save form fields into the MySql Database without submit button in jsp?  I want to store user inputs into the database using javasccript or ajax or jqury but without submit button. Form Contains three fields
Form validation using jQuery plug in & JSP
Form validation using jQuery plug in & JSP In this tutorial, we will discuss about form validation using jQuery plug in & display of submit content...; If the email /URL is not valid or  You press 'submit ' without entering
Login Box appears when a button on the webpage is clicked
Login Box appears when a button on the webpage is clicked  How to create a Login Box on a web page that appears only when a button that is already present on the page is clicked
Login Box appears when a button on the webpage is clicked
Login Box appears when a button on the webpage is clicked  How to create a Login Box on a web page that appears only when a button that is already present on the page is clicked
Login Box appears when a button on the webpage is clicked
Login Box appears when a button on the webpage is clicked  How to create a Login Box on a web page that appears only when a button that is already present on the page is clicked
How to view database for user when they login in netbeans and mysql?
How to view database for user when they login in netbeans and mysql?  I create a web page where when user login they have to fill in a form, after they click the button submit, the next page they going to see is the information
getting an error when set classpath
getting an error when set classpath  Hello Everyone! i have used hssf... for that jar file but when i compile the program it will compile correctly but when i run it, it gives an error "could not find or load main" please help me
why and where we use setter and getter methods in java, please give me one example program.....
why and where we use setter and getter methods in java, please give me one example program.....  why and where we use setter and getter methods in java, please give me one example program
print form information when click on print button
print form information when click on print button   Sir,I desingn institute webside using jsp and strut by using platform netbean 7.2.So request you please help for printing form information by clickin print button after submit
jsp login code ... when username , drop down box and password is correct
;td></td><td><input type="submit" value="Login"></td>...jsp login code ... when username , drop down box and password is correct  i need a jsp code for login.... when username password and dropdown box
Expand / Collapse form div when click on button
Expand / Collapse form div when click on button  Hi, I have a form integrated from Wufoo with iFrame code. If the user misses a field an error...://fortwoplease.wufoo.com/forms/z7x3k7/" title="Squeeze Page" rel="nofollow">Fill out my Wufoo form
Problem when resizing the form - Swing AWT
. But When we resize the form, the old JTextPane moves to its initial position...(); This works proper at that time but when we maximize(resize) the internal form... the form space at initial stage. we have a button to add a new JTextPane on the form
PHP HTML Form Submit Button
we just need a Html Submit button. <input type="submit" name... in input type, we can also use button image but at the moment we don't need to do... when you want to check if the form was really submitted or not. We have given
when update is done on parent object child object is also updated
when update is done on parent object child object is also updated  here is my code.. Hibernate-1...;/class> when am trying to update actual_object hibernate is also updating
this code will be problem it display the error again send jsp for registration form
this code will be problem it display the error again send jsp for registration form  I AM ENTERING THE DETAILS OFTER IT DISPLAY THE ERROR PLEASE...; <tr><td></td><td><input type="submit" value="Submit">
this code will be problem it display the error again send jsp for registration form
this code will be problem it display the error again send jsp for registration form  I AM ENTERING THE DETAILS OFTER IT DISPLAY THE ERROR PLEASE...; <tr><td></td><td><input type="submit" value="Submit">
getting error in your login form code
getting error in your login form code  i tried your code for login form but i am getting an error.the error is undefined index userid...   hi friend, your form's input must have following : <input type
Spring 4 MVC Login form Example with source code
Spring 4 MVC Login form Example: Learn how to make a Login form in Spring MVC... you the code for creating the Login form in Spring MVC. You can validate.... This is simple program which tells you how to make login form and validate
Swing login form example
Swing login form example In this example we have described swing login form... text for username and password. We create one submit button and perform... and password, an error message will be displayed for which we have used JOptionPane
jsp login code when username , password and dropdown box value is correct...
jsp login code when username , password and dropdown box value is correct... in dropdown box.... so when i login i all the three username,password and dropdown box...="submit" value="Login"></td></tr> </table> </form> <
jsp login code when username , password and dropdown box value is correct...
jsp login code when username , password and dropdown box value is correct... in dropdown box.... so when i login i all the three username,password and dropdown box...;</tr> <tr><td></td><td><input type="submit
Jsp error when i run this a jsp file
Jsp error when i run this a jsp file  hi I got this error when i run the jsp file in IDE and outside also please help me java.lang.NullPointerException org.apache.jsp.insertjsp.jspInit(insert_jsp.java:22
PHP Form Part-5
Topic : HTML FORM Part - 5 In the previous parts of this tutorial, we covered form attributes, input type attributes and Submit button attributes.  Now... tutorial, if you noticed we used name attribute in the input type. This attribute
Login or Cancel Application Using Ajax
implementation of login application with features like submit and cancel buttons using the Ajax (DOJO). This application also checks the user validation i.e.... with features like submit and cancel buttons. This login application first
struts2.2.1 Login validation example.
struts2.2.1 Login validation example. In this example, We will discuss about the Login validation using struts2.2.1. Directory structure of example...; charset=UTF-8"> <title>Login Validation Example<
 

 

 

DMCA.com