You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by da...@adw.es on 2008/07/18 20:28:36 UTC

Error global-Forwards

Hi, i have a problem, let me explain. I have one globalforward as a html:link defined in a jsp page, after clicking it, it should execute the corresponding action class and display the results in another jsp page.

Page1Link (global forward to *.do -- not to .jsp) -->calls actionClass.java -->  Page2 showing bean with retrieved data from actionClass (session scope)

The problem is that nothing happens , I mean nothing is displayed in the Page2 (nor data and html tags), and no System.out from ActionClass is displayed. In the navigator bar (MS internet explorer) appears: http://localhost:8080/myproject/actionClass.do

Any suggestion or ideas? I´ve been checking the struts-config.xml and do not know what could be wrong.

Thanks in advance,

Re: Error global-Forwards

Posted by Dani <da...@adw.es>.
Lukasz Lenart escribió:
>> public class MostrarUsuarioAction extends Action {
>>     
>
> You have to override execute() method not implement your own method,
> Struts1 will not use it. The deafult implementation just return null,
> so it means, stop processing.
> Change your method name mostrarUsuario() to execute() and should be ok.
>
> If you want to use different methods name's extends DispatchAction and
> add parameter attribute to your config.
>
>
> Regards
>   
Thanks for your answer. I have implemented DispatchAction method and it 
works fine. As this is my first "big" project in Struts, didn´t know 
about these "little details".
One more thing I have learnt ;-)

Best Regards !

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


Re: Error global-Forwards

Posted by Lukasz Lenart <lu...@googlemail.com>.
> public class MostrarUsuarioAction extends Action {

You have to override execute() method not implement your own method,
Struts1 will not use it. The deafult implementation just return null,
so it means, stop processing.
Change your method name mostrarUsuario() to execute() and should be ok.

If you want to use different methods name's extends DispatchAction and
add parameter attribute to your config.


Regards
-- 
Lukasz
http://www.lenart.org.pl/

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


Re: Error global-Forwards

Posted by Dani <da...@adw.es>.
Lukasz Lenart escribió:
> Copy-paste your jsp and/or action and we will see..
>
>
> Regards
>   
 I call the method getUsuarios() that should return all the idusers of 
the database (just created and working, tested) . This method returns an 
Arraylist (mostrar) which is saved in a bean session. Afterwards, the id 
users of this bean will be displayed in the mostrarUsuario.jsp page. As 
there are users in the DB, the lenght Arraylist should not be zero so 
the forward returned should be "success", and not "fail" . Note that the 
struts-config.xml has been changed from the last one, this is the good 
one -> mostrarUsuario action in session scope. However I obtain the same 
results with scope request, as described in the last mail:

--------------- This is the action MostrarUsuarioAction.java:  
------------------

package com.gentaiw.struts.action;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.sql.DataSource;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import com.gentaiw.struts.form.UserLogin2Form;

public class MostrarUsuarioAction extends Action {

        public ArrayList<UserLogin2Form> mostrar = new 
ArrayList<UserLogin2Form>();
      
    public ActionForward mostrarUsuario(ActionMapping mapping, 
ActionForm form,
            HttpServletRequest request, HttpServletResponse response) 
throws SQLException {
       
        HttpSession session = request.getSession(); //we create the session

        mostrar.clear();
        mostrar = getUsuarios(); //we call the getUsuarios method to 
obtain the users of the DB
        System.out.println("NUM ITEMS USUARIO LIST -> "+mostrar.size());
        session.setAttribute("mostrarlist", mostrar);
   
        if (mostrar.size()==0){
            return mapping.findForward("fail");   
        }else{
            return mapping.findForward("success");
        }

    }// END MOSTRAR USUARIO
   
    private ArrayList<UserLogin2Form> getUsuarios() throws SQLException {
       
        Connection conn = null;
        Statement stmt = null;
        ResultSet rs = null;
       
        try { //INI try
           
            DataSource dataSource = 
(DataSource)servlet.getServletContext().getAttribute("usuario"); //key 
datasource
           
            conn = dataSource.getConnection();
            conn.setAutoCommit(true);
            String sqlConsulta = "SELECT * FROM usuario";
            rs = stmt.executeQuery(sqlConsulta);
       
            while (rs.next()){ //INI while
                UserLogin2Form miUsuario = new UserLogin2Form();
                
System.out.println("USUARIO"+miUsuario.getIdusuario().toString());
                mostrar.add(miUsuario);
           
            } //END while
            rs.close();
            System.out.println("NUM ITEMS DENTRO USUARIO LIST -> 
"+mostrar.size());
        }//END try
       
            finally {
                if (rs!=null){
                    try{
                        rs.close();
                    } catch (SQLException sqlEx){ //ignore }
                    rs = null;
                    }
           
                if (stmt!=null){
                    try{
                        stmt.close();
                    } catch (SQLException sqlEx){ //ignore }
                    stmt = null;
                    }
                }
                }   
            }//END finally
           
            return mostrar;
    }
} //END


--- --------This is the JSP page mostrarUsuario.jsp : -------------

<%@ page language="java" pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
<%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html:html lang="true">
  <head>
    <html:base />
    <title>eliminarUsuario.jsp</title>
  </head>
  <body>Lista usuarios <br>
     <logic:iterate name="mostrarlist" id="list" scope="session"><br>
        <td>id usuario: <bean:write name="list" property="idusuario" 
/><td/><br>
    </logic:iterate>
   </body>
</html:html>


-------- Struts.config.xml ----------

    <action
      attribute="MostrarUsuarioForm"
      name="MostrarUsuarioForm"
      path="/mostrarUsuario"
      scope="session"
      type="com.gentaiw.struts.action.MostrarUsuarioAction"
      validate="false">
      <forward name="success" path="/mostrarUsuario.jsp" />
      <forward name="fail" path="/usuarioCreado.jsp" />
    </action>
--------------EOF-------------------

If you need any more info, just let me know. Thanks for your help.
Regards,


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


Re: Error global-Forwards

Posted by Lukasz Lenart <lu...@googlemail.com>.
Copy-paste your jsp and/or action and we will see..


Regards
-- 
Lukasz
http://www.lenart.org.pl/

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


Re: Error global-Forwards

Posted by Dan <da...@adw.es>.
Lukasz Lenart escribió:
>> Er..what is CamelHumps? No idea about it, sorry... :)
>>     
>
> You defined your path in config as /mostrarUsuario (CamelHumps -
> JavaClassNamingConvention) but you accessing it like below
> http://localhost:8080/gentaiw/mostrarusuario.do
>
> try this
> http://localhost:8080/gentaiw/mostrarUsuario.do
>
> As I remember, Tomcat distinct letter case ;-)
>
>
> Regards
>   
Well, in fact that´s the way i am accesing as defined in the 
struts-config.xml:

http://localhost:8080/gentaiw/mostrarUsuario.do

(the url i sent you was wrong -> http://localhost:8080/gentaiw/mostrarusuario.do
I wrote the url instead of copy&paste).

 Changed the name of the action to mostrarusuario.do and of course, gives me error 404 path not found. Anyway, ill check again my action and jsp  in case there is something wrong.
Regards,




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


Re: Error global-Forwards

Posted by Lukasz Lenart <lu...@googlemail.com>.
> Er..what is CamelHumps? No idea about it, sorry... :)

You defined your path in config as /mostrarUsuario (CamelHumps -
JavaClassNamingConvention) but you accessing it like below
http://localhost:8080/gentaiw/mostrarusuario.do

try this
http://localhost:8080/gentaiw/mostrarUsuario.do

As I remember, Tomcat distinct letter case ;-)


Regards
-- 
Lukasz
http://www.lenart.org.pl/

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


Re: Error global-Forwards

Posted by Dan <da...@adw.es>.
Lukasz Lenart escribió:
>> navigator bar and the window title (where the name of the actual jsp page is
>> displayed) appears the same name as in the nav bar:
>> http://localhost:8080/gentaiw/mostrarusuario.do , (mostrarusuario means
>> showuser) instead of mostrarUsuario.jsp
>>     
>
> This is correct behavior, you should never see any *.jsp in url, you
> should also consider to request your global forwards jsp through
> action and not directly.
>
>
> http://localhost:8080/gentaiw/mostrarUsuario.do
>
>
> Regards
>   
"This is correct behavior, you should never see any *.jsp in url, you
should also consider to request your global forwards jsp through
action and not directly."

Ok, i see what you mean but i need to display some info from one jsp page to another directly:
page1 -> click link -> get the info from action class -> display the info in page 2
I suppose there isn´t another approach...

"
Ok, back to you problem, the config looks ok, could you try access you
action with CamelHumps, as you configured in struts-config.xml?"
Er..what is CamelHumps? No idea about it, sorry... :) 

PD:( plus info: using myeclipse IDE if needed)

Regards,



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


Re: Error global-Forwards

Posted by Lukasz Lenart <lu...@googlemail.com>.
> navigator bar and the window title (where the name of the actual jsp page is
> displayed) appears the same name as in the nav bar:
> http://localhost:8080/gentaiw/mostrarusuario.do , (mostrarusuario means
> showuser) instead of mostrarUsuario.jsp

This is correct behavior, you should never see any *.jsp in url, you
should also consider to request your global forwards jsp through
action and not directly.
Ok, back to you problem, the config looks ok, could you try access you
action with CamelHumps, as you configured in struts-config.xml?

http://localhost:8080/gentaiw/mostrarUsuario.do


Regards
-- 
Lukasz
http://www.lenart.org.pl/

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


Re: Error global-Forwards

Posted by Dani <da...@adw.es>.
Lukasz Lenart escribió:
> Hi,
>
> Could you paste your struts-config here?
>
>
> Regards
>   
Hi,
This is the whole struts-config file. As fas as i can see, the problem 
has nothing to do with the actionClass itself, because I only put a 
simple forward in the action, and the result is the same as with the 
code i must program. The browser gets stucked in the action *.do, as if 
it would enter in a loop.No errors are shown in the Tomcat console nor 
the logs. In the navigator bar and the window title (where the name of 
the actual jsp page is displayed) appears the same name as in the nav 
bar: http://localhost:8080/gentaiw/mostrarusuario.do , (mostrarusuario 
means showuser) instead of mostrarUsuario.jsp
More info , the global forward   "<forward name="irMostrarTest" 
path="/mostrarConfigurarTest.do" />" works fine.

Best regards,


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD 
Struts Configuration 1.2//EN" 
"http://struts.apache.org/dtds/struts-config_1_2.dtd">

<struts-config>

    <data-sources>
    <data-source type="org.apache.commons.dbcp.BasicDataSource" 
key="usuario" >
        <set-property property="driverClassName" 
value="com.mysql.jdbc.Driver" />
        <set-property property="url" 
value="jdbc:mysql://localhost:3306/gentaidb?autoReconnect=true" />
        <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 usuario" />
    </data-source>
  </data-sources>
 
  <form-beans >
    <form-bean
      name="UserLogin2Form"
      type="com.gentaiw.struts.form.UserLogin2Form"/>
    <form-bean
      name="CrearUsuarioForm"
      type="com.gentaiw.struts.form.CrearUsuarioForm"/>
    <form-bean
      name="EliminarUsuarioForm"
      type="com.gentaiw.struts.form.UserLogin2Form"/>
    <form-bean name="ConfigurarTestForm"
    type="com.gentaiw.struts.form.ConfigurarTestForm" />
    <form-bean name="MostrarUsuarioForm"
    type="com.gentaiw.struts.form.MostrarUsuarioForm" />
  </form-beans>

  <global-exceptions />
  <global-forwards >
    <forward name="irLogin" path="/userLogin.jsp" />
    <forward name="irInicio" path="/inicio.jsp" />
    <forward name="irCrearUsuario" path="/crearUsuario.jsp" />
    <forward name="irEliminarUsuario" path="/eliminarUsuario.do" />
    <forward name="irActualizarUsuario" path="/actualizarUsuario.jsp" />
    <forward name="irMostrarTest" path="/mostrarConfigurarTest.do" />
    <forward name="irConfigurarTest" path="/configurarTest.jsp" />
    <forward name="irAdminMenu" path="/adminLoginSuccess.jsp" />
    <forward name="irUsuario" path="/mostrarUsuario.do" />
  </global-forwards>

  <action-mappings >
    <action
      path="/userLogin"
      input="/userLogin.jsp"
      name="UserLogin2Form"
      scope="session"
      attribute="listausuario"
      type="com.gentaiw.struts.action.UserLoginAction"
      validate="false">
      <forward name="userlogin" path="/userLogin.jsp" />
      <forward name="usuario" path="/userLoginSuccess.jsp" />
      <forward name="admin" path="/adminLoginSuccess.jsp" />
    </action>
    <action
      path="/crearUsuario"
      input="/crearUsuario.jsp"
      name="CrearUsuarioForm"
      scope="session"
      type="com.gentaiw.struts.action.CrearUsuarioAction"
      validate="false">
      <forward name="success" path="/usuarioCreado.jsp" />
    </action>
    <action
      attribute="MostrarUsuarioForm"
      name="MostrarUsuarioForm"
      path="/mostrarUsuario"
      scope="request"
      type="com.gentaiw.struts.action.MostrarUsuarioAction"
      validate="false">
      <forward name="success" path="/mostrarUsuario.jsp" />
    </action>
   
        <action
      input="/adminLoginSuccess.jsp"
      path="/eliminarUsuario"
      scope="request"
      type="com.gentaiw.struts.action.EliminarUsuarioAction"
      validate="false">
      <forward
        name="success"
        path="/eliminarUsuario.jsp" />
    </action>
      
    <action
      attribute="ConfigurarTestForm"
      name="ConfigurarTestForm"
      path="/mostrarConfigurarTest"
      scope="request"
      validate="false"
      type="com.gentaiw.struts.action.MostrarConfigurarTestAction">
      <forward name="success" path="/mostrarConfiguracionTest.jsp" />
    </action>
    <action
      attribute="ConfigurarTestForm"
        input="/configurarTest.jsp"
      name="ConfigurarTestForm"
      path="/configurarTest"
      scope="request"
      type="com.gentaiw.struts.action.ConfigurarTestAction"
      validate="true">
      <forward name="success" path="/configuracionGuardada.jsp" />
      <forward name="error" path="/errorConfigurar.jsp" />
      <forward name="input" path="/configurarTest.jsp" />
    </action>
  </action-mappings>
 
  <message-resources
      null="false"
      parameter="ApplicationResources" />
 
    <plug-in className="org.apache.struts.validator.ValidatorPlugIn">
      <set-property property="pathname2" value="/WEB-INF/validation.xml" />
      <set-property property="pathname1" 
value="/WEB-INF/validator-rules.xml" />
    </plug-in>
     
     
</struts-config>

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


Re: Error global-Forwards

Posted by Lukasz Lenart <lu...@googlemail.com>.
Hi,

Could you paste your struts-config here?


Regards
-- 
Lukasz
http://www.lenart.org.pl/

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