|
|||||||
|
|
|
![]() |
|
|
Strumenti |
|
|
#1 |
|
Junior Member
Iscritto dal: May 2005
Messaggi: 1
|
Errore con STRUTS!
Salve a tutti.
Da poco ho iniziato a programmare in j2ee con struts, ma è da un bel paio di giorni che sto impazzendo su un login che non ne vuole proprio sapere di funzionare! Sto impazzendo!!! Sono sull'orlo di una crisi di nervi! Per chiarezza vi posto gran parte dei file interessati. Io non sono riuscito a trovare errori... L'errore riscontrato è: HTTP Status 404 - Servlet action is not available --------------------------------------------------------- type Status report message Servlet action is not available description The requested resource (Servlet action is not available) is not available. Apache Tomcat/5.5.7 --------------------------------------------------------- La parte di configurazione di Struts-config.xml --------------------------------------------------------- <!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_2.dtd"> <!-- Struts configuration file --><struts-config> <!-- ============================================ Data Source Configuration --> <data-sources> <data-source type="org.apache.commons.dbcp.BasicDataSource"> <set-property property="driverClassName" value="org.gjt.mm.mysql.Driver" /> <set-property property="url" value="jdbc:mysql://localhost:3306/SiteLabLing" /> <set-property property="username" value="root" /> <set-property property="password" value="admin" /> <set-property property="maxActive" value="10" /> <set-property property="maxWait" value="5000" /> <set-property property="defaultAutoCommit" value="false" /> <set-property property="defaultReadOnly" value="false" /> <set-property property="validationQuery" value="SELECT COUNT(*) FROM market" /> </data-source> </data-sources> <!-- ================================================ Form Bean Definitions --> <form-beans> <!-- Login form bean --> <form-bean name="loginForm" type="org.apache.struts.webapp.login.LoginForm" /> <form-bean name="uploadForm" type="org.apache.struts.webapp.file.UploadForm" /> <form-bean name="downloadForm" type="org.apache.struts.webapp.file.DownloadForm" /> <form-bean name="listDocForm" type="org.apache.struts.webapp.file.ListDocForm" /> <form-bean name="emailForm" type="org.apache.struts.webapp.email.EmailForm" /> </form-beans> <!-- sample form bean descriptor for an ActionForm <form-bean name="inputForm" type="app.InputForm"/> end sample --> <!-- sample form bean descriptor for a DynaActionForm <form-bean name="logonForm" type="org.apache.struts.action.DynaActionForm"> <form-property name="username" type="java.lang.String"/> <form-property name="password" type="java.lang.String"/> </form-bean> end sample --> <!-- ========================================= Global Exception Definitions --> <global-exceptions> <exception type="" key="global.error.invalidLogin" path="/pages/Login.jsp" /> <!-- sample exception handler <exception key="expired.password" type="app.ExpiredPasswordException" path="/changePassword.jsp"/> end sample --> </global-exceptions> <!-- =========================================== Global Forward Definitions --> <global-forwards> <forward name="welcome" path="/Welcome.do" redirect="true" /> <forward name="login" path="/Login.do" redirect="true" /> <forward name="systemFailure" path="/SystemError.do" redirect="true" /> <forward name="sessionTimeOut" path="/SessionTimeOut.do" /> </global-forwards> <!-- =========================================== Action Mapping Definitions --> <action-mappings> <!-- In action l'attributo: path= rappresenta il nome della action name= rappresenta il nome della form -> uguale al form-bean--> <action path="/welcome" forward="/pages/Welcome.jsp" /> <!-- Per visualizzare la pagina di login --> <action path="/login" forward="pages/Login.jsp"/> <!-- Per processare il login --> <action path= "/submitLogin" type= "org.apache.struts.webapp.login.LoginAction" name= "loginForm" scope= "request" validate= "true" input= "/pages/Login.jsp"> <forward name="errorDb" path="/pages/Login.jsp" /> <forward name="errorLogin" path="/pages/Login.jsp" /> <forward name="pagStud" path="/pages/pageStud.jsp" /> <forward name="pagProf" path="/pages/pageProf.jsp" /> </action> Il file Login.jsp --------------------------------------------------------- <%@ taglib uri="/tags/struts-html" prefix="html" %> <%@ taglib uri="/tags/struts-bean" prefix="bean" %> <%@ page contentType="text/html"%> <%@ page pageEncoding="UTF-8"%> <!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"> <link href="style.css" rel="stylesheet" type="text/css"> <title>Login</title> </head> <body> <center> <font class="title"><b>Login Page</b></font> <br/><br/> <html:errors/> <html:form action="submitLogin"> <table> <tr> <td align="right">Nome:</td> <td align="left"><html:text property="nome" size="18" /></td> </tr> <tr> <td align="right">Password:</td> <td align="left"><html: password property="password" size="18" maxlength="18" redisplay="false" /></td> </tr> <tr> <td align="right"> <html:submit>Login</html:submit> </td> <td align="left"> <html:reset>Cancella</html:reset> </td> </tr> </table> </html:form> </font> </center> </body> </html> Il file LoginAction --------------------------------------------------------- package org.apache.struts.webapp.login; import java.io.*; import java.sql.*; import java.lang.*; import javax.servlet.http.*; import org.apache.struts.action.*; //========================================== // ...paginaStruts //========================================== public final class LoginAction extends Action { public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { if (form instanceof LoginForm) { //========================================== // Aquisizione da Form //========================================== LoginForm loginForm = (LoginForm) form; // -------> Aquisizione parametri dal form String nome = loginForm.getNome(); String password = loginForm.getPassword(); //========================================== // Provvediamo alla connesione col Database. //========================================== javax.sql.DataSource dataSource; java.sql.Connection myConnection=null; try { dataSource = getDataSource(request); myConnection = dataSource.getConnection(); //========================================== // Interroghiamo il Database... //========================================== Statement stm = myConnection.createStatement(); // Interrogo il DBMS mediante una query SQL. // Creo una tabella e vi inserisco dei dati // Stampo su schermo la tabella ResultSet resultset = stm.executeQuery( "SELECT Id, Nome, Password, Ident FROM Studenti, Professori"); // Scorro i risultati. while (resultset.next()) { String id = resultset.getString(1); String nomeR = resultset.getString(2); String passwordR = resultset.getString(3); String ident = resultset.getString(4); if((nomeR==nome)&&(passwordR==password)){ if(ident=="stud"){ //========================================== // Blocco sessione_inizio // // Invalidiamo la sessione se esiste già HttpSession session = request.getSession(false); if(session != null) { session.invalidate(); } // Creiamo una sessione per questo utente session = request.getSession(true); // Setto gli attributi della sessione // si tratta di coppie nome/valore session.setAttribute("ID", id ); session.setAttribute("NOME", nome ); session.setAttribute("PASSWORD", password ); session.setAttribute("IDENT", ident ); // Blocco sessione_fine //========================================== return mapping.findForward("pagStud"); } if(ident=="prof"){ //========================================== // Blocco sessione_inizio // // Invalidiamo la sessione se esiste già HttpSession session = request.getSession(false); if(session != null) { session.invalidate(); } // Creiamo una sessione per questo utente session = request.getSession(true); // Store the UserView into the session and return session.setAttribute( nome, password ); // Blocco sessione_fine //========================================== return mapping.findForward("pagProf"); } } else{ // errore: non si trova nelle tabelle // -> si return mapping.findForward("errorLogin"); } } //========================================== // Per eventuali eccezioni... //========================================== } catch (SQLException e) { // getServlet().log("Connection.process", sqle); return mapping.findForward("errorDb"); } finally { //enclose this in a finally block to make //sure the connection is closed try { myConnection.close(); } catch (SQLException e) { // connessione terminata // getServlet().log("Connection.close", e); return mapping.findForward("errorDb"); } } return mapping.findForward("errorLogin"); } return null; } } Il file LoginForm --------------------------------------------------------- package org.apache.struts.webapp.login; import org.apache.struts.action.*; import javax.servlet.http.*; public final class LoginForm extends ActionForm { // --------------------------------------------------- Instance Variables /** * An example String property. */ private String password = null; private String nome = null; // ----------------------------------------------------------- Properties /** * Return the password String. */ public String getPassword() { return (this.password); } /** * Set the password String. * @param password The new password String. */ public void setPassword(String password) { this.password = password; } // ---------------------------------------> passiamo al nome /** * Return the nome String. */ public String getNome() { return (this.nome); } /** * Set the nome String. * @param nome The new nome String. */ public void setNome(String nome) { this.nome = nome; } // --------------------------------------------> validazione public ActionErrors validate(ActionMapping mapping, HttpServletRequest request){ ActionErrors errors=new ActionErrors(); if((nome==null)||(nome.length()<1)) errors.add("nome", new ActionError("errors.name.obblig")); if((password==null)||(password.length()<1)) errors.add("password", new ActionError("errors.password.obblig")); return errors; } } Aiutatemi! Ho provato decine e decine di volte! Ho chiesto a diversi forum, ma nessuno è riuscito a dirmi che errore c'è nel codice! Grazie. Ultima modifica di _Nirvana_ : 29-05-2005 alle 19:33. |
|
|
|
|
| Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 06:50.



















