DissertationsEnLigne.com - Dissertations gratuites, mémoires, discours et notes de recherche
Recherche

Java J2Ee Struts1.3.10

Compte Rendu : Java J2Ee Struts1.3.10. Rechercher de 53 000+ Dissertation Gratuites et Mémoires
Page 1 sur 3

port javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import import import import org.apache.struts.action.Action; org.apache.struts.action.ActionForm; org.apache.struts.action.ActionForward; org.apache.struts.action.ActionMapping;

public class Logout extends Action { public ActionForward execute( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception{ try{ HttpSession session = request.getSession(false); if(session!=null) { session.invalidate(); }

}catch(Exception e){ String strError=e.getMessage(); System.out.println("Error is: " + strError); }

return mapping.findForward("success"); }

}

UserLoginForm.java

package jeha.web.struts.form;

import javax.servlet.http.HttpServletRequest; import org.apache.struts.action.*; public class UserLoginForm extends ActionForm{ private String action="add"; private String userid = null; private String password = null;

public void reset(ActionMapping mapping,HttpServletRequest request){ this.userid=null; this.password=null; this.action="add"; } public ActionErrors validate( ActionMapping mapping, HttpServletRequest request ) { ActionErrors errors = new ActionErrors(); return errors; }

public String getAction() { return action; }

public void setAction(String action) { this.action = action; }

public String getPassword() { return password; }

public void setPassword(String password) { this.password = password; }

public String getUserid() { return userid; }

public void setUserid(String userid) { this.userid = userid; }

}

UserLoginAction.java

package jeha.web.struts.action; import import import import jeha.web.struts.form.UserLoginForm; javax.servlet.http.HttpServletRequest; javax.servlet.http.HttpServletResponse; javax.servlet.http.HttpSession;

import import import import import import

org.apache.struts.action.Action; org.apache.struts.action.ActionForm; org.apache.struts.action.ActionForward; org.apache.struts.action.ActionMapping; org.apache.struts.action.ActionMessage; org.apache.struts.action.ActionMessages;

public class UserLoginAction

extends Action{

public ActionForward execute( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception{ boolean loginStatus =false; // Create object of ActionMesssages ActionMessages errors = new ActionMessages(); UserLoginForm objForm = (UserLoginForm) form;

String strUserid=objForm.getUserid(); String strPassword=objForm.getPassword(); if(strUserid.equals("jeha") && strPassword.equals("123") ){ loginStatus = true; }

if(loginStatus==true){ HttpSession request.getSession(); try{ } catch (Exception e) { System.out.println("===> Error:" + e.getMessage()); } session.setAttribute("userID", strUserid); return mapping.findForward("success"); } else { // not allowed errors.add("login",new ActionMessage("error.login.invalid")); saveErrors(request,errors); return mapping.findForward("failure"); } } } session =

MessageResources.properties

welcome.title=Struts JEHA Application welcome.heading=Welcome! error.login.invalid=Invalid User Name Or Password !

Etape 10 Exécuter l’application

Fin.

...

Télécharger au format  txt (5 Kb)   pdf (72 Kb)   docx (7.1 Kb)  
Voir 2 pages de plus »
Uniquement disponible sur DissertationsEnLigne.com