**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>
Please visit the following links:
http://www.roseindia.net/struts/struts/struts2.2.1/tags/LonginValidation.html
http://www.roseindia.net/struts/struts2/struts2validation.shtml
Ads