You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by alexj <al...@freesurf.ch> on 2003/02/10 18:42:16 UTC

trouble

Hi I can't figure what I've missed into my code :
here is my login.jsp
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>

<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>

<html>

<body>

<center>

<img border="0" src="images/soft-intro.gif" width="368" height="321">

<html:form action="/login">

<table width="45%" border="1" style="border-collapse: collapse">

<tr>

<td><bean:message key='app.userName'/></td>

<td align="center"><html:text property="userName" /> </td>

</tr>

<tr>

<td><bean:message key='app.userPassword'/></td>

<td align="center"><html:password property="userPassword" /></td>

</tr>

<tr>

<td colspan="2" align="center"><html:submit/> </td>

</tr>

</table>

<html:errors />

</html:form>

</center>

</body>

</html>



My login form :

// Created by Xslt generator for Eclipse.

// XSL : not found (java.io.FileNotFoundException: (Le chemin d'accès
spécifié est introuvable))

// Default XSL used : easystruts.jar$org.easystruts.xslgen.JavaClass.xsl

package soft.ibmss.struts.form;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionErrors;

import org.apache.struts.action.ActionError;

import org.apache.struts.action.ActionForm;

import org.apache.struts.action.ActionMapping;

/**

* @author alexj

* To change this generated comment edit the template variable "typecomment":

* Window>Preferences>Java>Templates.

* To enable and disable the creation of type comments go to

* Window>Preferences>Java>Code Generation.

*

* LoginForm.java created by EasyStruts - XsltGen.

* http://easystruts.sf.net

* created on 02-10-2003

*

* XDoclet definition:

* @struts:form name="loginForm"

*/

public class LoginForm extends ActionForm {

// --------------------------------------------------------- Instance
Variables

/** userPassword property */

private String userPassword;

/** userName property */

private String userName;

// --------------------------------------------------------- Methods

/**

* Method validate

* @param ActionMapping mapping

* @param HttpServletRequest request

* @return ActionErrors

*/

public ActionErrors validate(

ActionMapping mapping,

HttpServletRequest request) {

ActionErrors errors = new ActionErrors ();

if ((userName == null) || (userName.length() == 0)) {

errors.add("userName", new ActionError ("errors.userNameRequired"));

}

if (userPassword == null) {

errors.add("userPassword", new ActionError ("errors.userPasswordRequired"));

}

return errors;

}

/**

* Method reset

* @param ActionMapping mapping

* @param HttpServletRequest request

*/

public void reset(ActionMapping mapping, HttpServletRequest request) {

userPassword = "";

userName = "";

}

/**

* Returns the userPassword.

* @return String

*/

public String getUserPassword() {

return userPassword;

}

/**

* Set the userPassword.

* @param userPassword The userPassword to set

*/

public void setUserPassword(String userPassword) {

this.userPassword = userPassword;

}

/**

* Returns the userName.

* @return String

*/

public String getUserName() {

return userName;

}

/**

* Set the userName.

* @param userName The userName to set

*/

public void setUserName(String userName) {

this.userName = userName;

}

}

my login action :



// Created by Xslt generator for Eclipse.

// XSL : not found (java.io.FileNotFoundException: (Le chemin d'accès
spécifié est introuvable))

// Default XSL used : easystruts.jar$org.easystruts.xslgen.JavaClass.xsl

package soft.ibmss.struts.action;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

import javax.servlet.ServletContext;

import javax.servlet.http.HttpSession;

import java.sql.Connection;

import javax.sql.DataSource;

import java.sql.Statement;

import java.sql.ResultSet;

import java.sql.SQLException;

import org.apache.struts.action.Action;

import org.apache.struts.action.ActionErrors;

import org.apache.struts.action.ActionError;

import org.apache.struts.action.ActionForm;

import org.apache.struts.action.ActionForward;

import org.apache.struts.action.ActionMapping;

import soft.ibmss.struts.form.LoginForm;

import org.apache.struts.Globals;

import java.util.Vector;

/**

* @author alexj

* XDoclet definition:

* @struts:action path="/login" name="loginForm" input="/login.jsp"
validate="true"

* @struts:action-forward name="" path=""

*/

public class LoginAction extends Action {

// --------------------------------------------------------- Instance
Variables

// --------------------------------------------------------- Methods

/**

* Method execute

* @param ActionMapping mapping

* @param ActionForm form

* @param HttpServletRequest request

* @param HttpServletResponse response

* @return ActionForward

* @throws Exception

*/

public ActionForward execute(

ActionMapping mapping,

ActionForm form,

HttpServletRequest request,

HttpServletResponse response)

throws Exception {


String target = new String ("success");

LoginForm loginForm = (LoginForm) form;

String userName = ((LoginForm) form).getUserName();

String userPassword = ((LoginForm) form).getUserPassword();

String user = getUser(userName, userPassword);

if (user == null) {

target = new String ("login");

ActionErrors errors = new ActionErrors ();

errors.add(ActionErrors.GLOBAL_ERROR, new ActionError (

"errors.userNotFound", userName));

saveErrors(request, errors) ;

}

else {

HttpSession session = request.getSession();

session.setAttribute("USER :", user);

}

return (mapping.findForward(target));

}


/**

* Method getUser

* @param String userName

* @param String userPassword

* @return String

*/





public String getUser (String userName, String userPassword) {

String user = null;

Connection conn = null;

Statement stmt = null;

ResultSet rs = null;

DataSource dataSource = (DataSource)
servlet.getServletContext().getAttribute(Globals.DATA_SOURCE_KEY);

try {

conn = dataSource.getConnection();

stmt = conn.createStatement();

rs = stmt.executeQuery("SELECT nom_utilisateur, mot_de_passe FROM personne
WHERE nom_utilisateur = " +

"'" + userName + "'" +"AND mot_de_passe = " + "'" + userPassword + "'");

if (rs.next ()) {

user = rs.getString("nom_utilisateur");

}

}

catch (Exception ex) {


}

return user;

}



public Vector getGroupe (String userName, String userPassword) {

String user = null;

Connection conn = null;

Statement stmt = null;

ResultSet rs = null;

Vector result = new Vector ();

DataSource dataSource = (DataSource)
servlet.getServletContext().getAttribute(Globals.DATA_SOURCE_KEY);

try {

conn = dataSource.getConnection();

stmt = conn.createStatement();

rs = stmt.executeQuery("....");

while (rs.next ()) {

result.add(new String (rs.getString("groupe.nom")));

}

}

catch (Exception ex) {

System.out.println (ex.getMessage());

}

finally {


}

return result;

}


private void closeAll (ResultSet rs, Connection conn, Statement stmt) {


if (rs != null) {

try {

rs.close();

}

catch (Exception ex) {

System.out.println (ex.getMessage());

}

}

if (stmt != null) {

try {

stmt.close();

}

catch (Exception ex) {

System.out.println (ex.getMessage());

}

}

if (conn != null) {

try {

conn.close();

}

catch (Exception ex) {

System.out.println (ex.getMessage());

}

}

}

}

And finally my App.properties :

# Resources for parameter 'soft.ibmss.struts.ApplicationResources'

# Project P/ibmss

app.userName=Nom d'utilisateur :

app.userPassword=Mot de passe :

app.personName=Nom

app.personFirstName=Prénom

app.personBirthDate=Date de naissance

app.personInsurance=Assurance

app.personInsuranceNb=No d'assuré

app.personBankName=Banque

app.personBankAccount=No de compte

app.personAdress=Adresse

app.personCity=City

app.personNpa=Npa

app.personGroup=Groupe

errors.header=<h3>\

<font color='red'> Liste des erreurs</font></h3>

<ul>

errors.footer=</ul></hr>

errors.userNameRequired=<font color='red'>Nom d'utilisateur requis</font>

errors.userPasswordRequired=<font color='red'>Mot de passe requis</font>

errors.userNotFound=<font color='red'>Nom d'utilisateur ou mot de passe non
valide</font>



Any idea ??

Thanks in advance.

<--
Alexandre Jaquet
->


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: trouble

Posted by alexj <al...@freesurf.ch>.
I just saw my mapping definition was incomplete ... :))

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: trouble

Posted by alexj <al...@freesurf.ch>.
Here follow my mapping 

<action-mappings type="org.apache.struts.action.ActionMapping">

<action

attribute="loginForm"

input="/login.jsp"

name="loginForm"

validate="true"

path="/login"

type="soft.ibmss.struts.action.LoginAction">

<forward name="success" path="/ok.jsp" />

<forward name="login" path="/login.jsp" />

<forward name="student" path="" />

<forward name="prof" path="" />

</action>

----- Original Message ----- 
From: "Sean Dockery" <se...@sbdconsultants.com>
To: "Struts Users Mailing List" <st...@jakarta.apache.org>
Sent: Tuesday, February 11, 2003 12:16 AM
Subject: Re: <html:errors /> trouble


> What forwards are defined for your action in struts-config.xml?
> 
> 
> ----- Original Message ----- 
> From: "alexj" <al...@freesurf.ch>
> To: "Struts Users Mailing List" <st...@jakarta.apache.org>
> Sent: Monday, February 10, 2003 10:56
> Subject: Re: <html:errors /> trouble
> 
> 
> > (in fact when I run the app and enter bad datas I didn't get any
> > errors message displayed on my login page)
> > 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: trouble

Posted by Sean Dockery <se...@sbdconsultants.com>.
What forwards are defined for your action in struts-config.xml?


----- Original Message ----- 
From: "alexj" <al...@freesurf.ch>
To: "Struts Users Mailing List" <st...@jakarta.apache.org>
Sent: Monday, February 10, 2003 10:56
Subject: Re: <html:errors /> trouble


> (in fact when I run the app and enter bad datas I didn't get any
> errors message displayed on my login page)
> 



---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: trouble

Posted by alexj <al...@freesurf.ch>.
(in fact when I run the app and enter bad datas I didn't get any
errors message displayed on my login page)

----- Original Message -----
From: "alexj" <al...@freesurf.ch>
To: "Struts Users Mailing List" <st...@jakarta.apache.org>
Sent: Monday, February 10, 2003 6:42 PM
Subject: <html:errors /> trouble


> Hi I can't figure what I've missed into my code :
> here is my login.jsp
> <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>
>
> <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
>
> <html>
>
> <body>
>
> <center>
>
> <img border="0" src="images/soft-intro.gif" width="368" height="321">
>
> <html:form action="/login">
>
> <table width="45%" border="1" style="border-collapse: collapse">
>
> <tr>
>
> <td><bean:message key='app.userName'/></td>
>
> <td align="center"><html:text property="userName" /> </td>
>
> </tr>
>
> <tr>
>
> <td><bean:message key='app.userPassword'/></td>
>
> <td align="center"><html:password property="userPassword" /></td>
>
> </tr>
>
> <tr>
>
> <td colspan="2" align="center"><html:submit/> </td>
>
> </tr>
>
> </table>
>
> <html:errors />
>
> </html:form>
>
> </center>
>
> </body>
>
> </html>
>
>
>
> My login form :
>
> // Created by Xslt generator for Eclipse.
>
> // XSL : not found (java.io.FileNotFoundException: (Le chemin d'accès
> spécifié est introuvable))
>
> // Default XSL used : easystruts.jar$org.easystruts.xslgen.JavaClass.xsl
>
> package soft.ibmss.struts.form;
>
> import javax.servlet.http.HttpServletRequest;
>
> import org.apache.struts.action.ActionErrors;
>
> import org.apache.struts.action.ActionError;
>
> import org.apache.struts.action.ActionForm;
>
> import org.apache.struts.action.ActionMapping;
>
> /**
>
> * @author alexj
>
> * To change this generated comment edit the template variable
"typecomment":
>
> * Window>Preferences>Java>Templates.
>
> * To enable and disable the creation of type comments go to
>
> * Window>Preferences>Java>Code Generation.
>
> *
>
> * LoginForm.java created by EasyStruts - XsltGen.
>
> * http://easystruts.sf.net
>
> * created on 02-10-2003
>
> *
>
> * XDoclet definition:
>
> * @struts:form name="loginForm"
>
> */
>
> public class LoginForm extends ActionForm {
>
> // --------------------------------------------------------- Instance
> Variables
>
> /** userPassword property */
>
> private String userPassword;
>
> /** userName property */
>
> private String userName;
>
> // --------------------------------------------------------- Methods
>
> /**
>
> * Method validate
>
> * @param ActionMapping mapping
>
> * @param HttpServletRequest request
>
> * @return ActionErrors
>
> */
>
> public ActionErrors validate(
>
> ActionMapping mapping,
>
> HttpServletRequest request) {
>
> ActionErrors errors = new ActionErrors ();
>
> if ((userName == null) || (userName.length() == 0)) {
>
> errors.add("userName", new ActionError ("errors.userNameRequired"));
>
> }
>
> if (userPassword == null) {
>
> errors.add("userPassword", new ActionError
("errors.userPasswordRequired"));
>
> }
>
> return errors;
>
> }
>
> /**
>
> * Method reset
>
> * @param ActionMapping mapping
>
> * @param HttpServletRequest request
>
> */
>
> public void reset(ActionMapping mapping, HttpServletRequest request) {
>
> userPassword = "";
>
> userName = "";
>
> }
>
> /**
>
> * Returns the userPassword.
>
> * @return String
>
> */
>
> public String getUserPassword() {
>
> return userPassword;
>
> }
>
> /**
>
> * Set the userPassword.
>
> * @param userPassword The userPassword to set
>
> */
>
> public void setUserPassword(String userPassword) {
>
> this.userPassword = userPassword;
>
> }
>
> /**
>
> * Returns the userName.
>
> * @return String
>
> */
>
> public String getUserName() {
>
> return userName;
>
> }
>
> /**
>
> * Set the userName.
>
> * @param userName The userName to set
>
> */
>
> public void setUserName(String userName) {
>
> this.userName = userName;
>
> }
>
> }
>
> my login action :
>
>
>
> // Created by Xslt generator for Eclipse.
>
> // XSL : not found (java.io.FileNotFoundException: (Le chemin d'accès
> spécifié est introuvable))
>
> // Default XSL used : easystruts.jar$org.easystruts.xslgen.JavaClass.xsl
>
> package soft.ibmss.struts.action;
>
> import javax.servlet.http.HttpServletRequest;
>
> import javax.servlet.http.HttpServletResponse;
>
> import javax.servlet.ServletContext;
>
> import javax.servlet.http.HttpSession;
>
> import java.sql.Connection;
>
> import javax.sql.DataSource;
>
> import java.sql.Statement;
>
> import java.sql.ResultSet;
>
> import java.sql.SQLException;
>
> import org.apache.struts.action.Action;
>
> import org.apache.struts.action.ActionErrors;
>
> import org.apache.struts.action.ActionError;
>
> import org.apache.struts.action.ActionForm;
>
> import org.apache.struts.action.ActionForward;
>
> import org.apache.struts.action.ActionMapping;
>
> import soft.ibmss.struts.form.LoginForm;
>
> import org.apache.struts.Globals;
>
> import java.util.Vector;
>
> /**
>
> * @author alexj
>
> * XDoclet definition:
>
> * @struts:action path="/login" name="loginForm" input="/login.jsp"
> validate="true"
>
> * @struts:action-forward name="" path=""
>
> */
>
> public class LoginAction extends Action {
>
> // --------------------------------------------------------- Instance
> Variables
>
> // --------------------------------------------------------- Methods
>
> /**
>
> * Method execute
>
> * @param ActionMapping mapping
>
> * @param ActionForm form
>
> * @param HttpServletRequest request
>
> * @param HttpServletResponse response
>
> * @return ActionForward
>
> * @throws Exception
>
> */
>
> public ActionForward execute(
>
> ActionMapping mapping,
>
> ActionForm form,
>
> HttpServletRequest request,
>
> HttpServletResponse response)
>
> throws Exception {
>
>
> String target = new String ("success");
>
> LoginForm loginForm = (LoginForm) form;
>
> String userName = ((LoginForm) form).getUserName();
>
> String userPassword = ((LoginForm) form).getUserPassword();
>
> String user = getUser(userName, userPassword);
>
> if (user == null) {
>
> target = new String ("login");
>
> ActionErrors errors = new ActionErrors ();
>
> errors.add(ActionErrors.GLOBAL_ERROR, new ActionError (
>
> "errors.userNotFound", userName));
>
> saveErrors(request, errors) ;
>
> }
>
> else {
>
> HttpSession session = request.getSession();
>
> session.setAttribute("USER :", user);
>
> }
>
> return (mapping.findForward(target));
>
> }
>
>
> /**
>
> * Method getUser
>
> * @param String userName
>
> * @param String userPassword
>
> * @return String
>
> */
>
>
>
>
>
> public String getUser (String userName, String userPassword) {
>
> String user = null;
>
> Connection conn = null;
>
> Statement stmt = null;
>
> ResultSet rs = null;
>
> DataSource dataSource = (DataSource)
> servlet.getServletContext().getAttribute(Globals.DATA_SOURCE_KEY);
>
> try {
>
> conn = dataSource.getConnection();
>
> stmt = conn.createStatement();
>
> rs = stmt.executeQuery("SELECT nom_utilisateur, mot_de_passe FROM personne
> WHERE nom_utilisateur = " +
>
> "'" + userName + "'" +"AND mot_de_passe = " + "'" + userPassword + "'");
>
> if (rs.next ()) {
>
> user = rs.getString("nom_utilisateur");
>
> }
>
> }
>
> catch (Exception ex) {
>
>
> }
>
> return user;
>
> }
>
>
>
> public Vector getGroupe (String userName, String userPassword) {
>
> String user = null;
>
> Connection conn = null;
>
> Statement stmt = null;
>
> ResultSet rs = null;
>
> Vector result = new Vector ();
>
> DataSource dataSource = (DataSource)
> servlet.getServletContext().getAttribute(Globals.DATA_SOURCE_KEY);
>
> try {
>
> conn = dataSource.getConnection();
>
> stmt = conn.createStatement();
>
> rs = stmt.executeQuery("....");
>
> while (rs.next ()) {
>
> result.add(new String (rs.getString("groupe.nom")));
>
> }
>
> }
>
> catch (Exception ex) {
>
> System.out.println (ex.getMessage());
>
> }
>
> finally {
>
>
> }
>
> return result;
>
> }
>
>
> private void closeAll (ResultSet rs, Connection conn, Statement stmt) {
>
>
> if (rs != null) {
>
> try {
>
> rs.close();
>
> }
>
> catch (Exception ex) {
>
> System.out.println (ex.getMessage());
>
> }
>
> }
>
> if (stmt != null) {
>
> try {
>
> stmt.close();
>
> }
>
> catch (Exception ex) {
>
> System.out.println (ex.getMessage());
>
> }
>
> }
>
> if (conn != null) {
>
> try {
>
> conn.close();
>
> }
>
> catch (Exception ex) {
>
> System.out.println (ex.getMessage());
>
> }
>
> }
>
> }
>
> }
>
> And finally my App.properties :
>
> # Resources for parameter 'soft.ibmss.struts.ApplicationResources'
>
> # Project P/ibmss
>
> app.userName=Nom d'utilisateur :
>
> app.userPassword=Mot de passe :
>
> app.personName=Nom
>
> app.personFirstName=Prénom
>
> app.personBirthDate=Date de naissance
>
> app.personInsurance=Assurance
>
> app.personInsuranceNb=No d'assuré
>
> app.personBankName=Banque
>
> app.personBankAccount=No de compte
>
> app.personAdress=Adresse
>
> app.personCity=City
>
> app.personNpa=Npa
>
> app.personGroup=Groupe
>
> errors.header=<h3>\
>
> <font color='red'> Liste des erreurs</font></h3>
>
> <ul>
>
> errors.footer=</ul></hr>
>
> errors.userNameRequired=<font color='red'>Nom d'utilisateur requis</font>
>
> errors.userPasswordRequired=<font color='red'>Mot de passe requis</font>
>
> errors.userNotFound=<font color='red'>Nom d'utilisateur ou mot de passe
non
> valide</font>
>
>
>
> Any idea ??
>
> Thanks in advance.
>
> <--
> Alexandre Jaquet
> ->
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org