Re: Issue with Namespace Configuration

2025-06-11 Thread Joseph Huynh
 Hi Lukasz,
Sorry, it was a false alarm to report Struts2 failed to dispatch in case of 
duplicate names in the same namespace. I used System.out to monitor the flow 
and I didn't see what I expected to see and thought it silently failed. I now 
switch to log4j2 framework and can verify the flow from both console and log 
file. It is logical to return viewRegistration after the registration is 
successfully done.
Thank you for the links! After I get myself comfortable with Struts2 and 
complete the migration to Struts2 from Struts1 for all our applications, I will 
definitely work on moving from Ant build to Maven. Thank you again!
Regards,Joseph
On Wednesday, June 11, 2025 at 01:20:51 AM EDT, Lukasz Lenart 
 wrote:  
 
 śr., 11 cze 2025 o 00:59 Joseph Huynh 
napisał(a):
>
>  Hi Lukasz,
> I just figured out that I had bundled struts.xml in wrong place in WEB-INF/ 
> instead of in WEB-INF/classes/. It is dispatching correctly now. My 
> struts.xml is mostly fine except for the duplicate result name in the same 
> namespace. I think Struts2 fails (silently) to dispatch in this case because 
> it won't do anything, no errors either.

Duplicated result names don't matter, result names are "action local".
This means you can have an action named "viewRegistration" and at the
same time another action could have a result named "viewRegistration".
Basically the flow is as: http request -> action (by name) -> result
(by name for this action)

> I would love to learn to use Maven. I've tried several times in the past but 
> not successful.

Just install Maven and use archetypes to generate your application,
all modern IDEs support Maven out-of-box. Follow these steps
https://struts.apache.org/maven-archetypes/
https://struts.apache.org/getting-started/

If unclear please let me know and I will update the docs.


Cheers
Lukasz

-
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

  

Re: Issue with Namespace Configuration

2025-06-10 Thread Lukasz Lenart
śr., 11 cze 2025 o 00:59 Joseph Huynh 
napisał(a):
>
>  Hi Lukasz,
> I just figured out that I had bundled struts.xml in wrong place in WEB-INF/ 
> instead of in WEB-INF/classes/. It is dispatching correctly now. My 
> struts.xml is mostly fine except for the duplicate result name in the same 
> namespace. I think Struts2 fails (silently) to dispatch in this case because 
> it won't do anything, no errors either.

Duplicated result names don't matter, result names are "action local".
This means you can have an action named "viewRegistration" and at the
same time another action could have a result named "viewRegistration".
Basically the flow is as: http request -> action (by name) -> result
(by name for this action)

> I would love to learn to use Maven. I've tried several times in the past but 
> not successful.

Just install Maven and use archetypes to generate your application,
all modern IDEs support Maven out-of-box. Follow these steps
https://struts.apache.org/maven-archetypes/
https://struts.apache.org/getting-started/

If unclear please let me know and I will update the docs.


Cheers
Lukasz

-
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]



Re: Issue with Namespace Configuration

2025-06-10 Thread Joseph Huynh
 Hi Lukasz,
I just figured out that I had bundled struts.xml in wrong place in WEB-INF/ 
instead of in WEB-INF/classes/. It is dispatching correctly now. My struts.xml 
is mostly fine except for the duplicate result name in the same namespace. I 
think Struts2 fails (silently) to dispatch in this case because it won't do 
anything, no errors either.
I would love to learn to use Maven. I've tried several times in the past but 
not successful.
Thanks,Joseph H.
On Tuesday, June 10, 2025 at 03:25:44 AM EDT, Lukasz Lenart 
 wrote:  
 
 Is there a chance to expose source code of your app on Github? And I
would suggest learning how to use Maven to build the app instead of
Ant.

Cheers
Lukasz

pt., 6 cze 2025 o 18:49 Joseph Huynh 
napisał(a):
>
>  Hello,
> I have a simple web application to learn how the controller works in Struts 
> framework. The build is deployed to Tomcat 11.0.5. The application has two 
> simple JSP files PgStudent.jsp (configured as the welcome page) and 
> PgRegistration.jsp. Each page has two buttons to let user go back and forth 
> between the two pages. It loads the welcome page PgStudent fine, but any 
> request will encounter web error 404, like this one: There is no Action 
> mapped for namespace [/] and action name [viewRegistration] associated with 
> context path [/s2ex1], or from localhost_access log: 0:0:0:0:0:0:0:1 - - 
> [06/Jun/2025:12:12:28 -0400] "POST /s2ex1/viewRegistration HTTP/1.1" 404 829.
> Please help see where I do it wrong. Namespace is specified in JSP files, but 
> it always sees namespace as /. I am attaching the project file structure and 
> the list of the files:
> Project Files Structure
> s2ex1    lib        caffeine-3.1.8.jar        freemarker-2.3.34.jar        
> jakarta.servlet-api-5.0.0.jar (to compile only)        ognl-3.3.5.jar        
> struts2-core-7.0.3.jar        xwork-core-2.3.35.jar    src        s2ex1       
>      RegistrationAction.java            StudentAction.java    WebContent      
>   jsp            PgRegistration.jsp            PgStudent.jsp        WEB-INF   
>          struts.xml            web.xml    build.xml
> List of the 7 files
> 1. struts.xml "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"    
> "https://struts.apache.org/dtds/struts-2.0.dtd";>  name="struts.devMode" value="true"/>       name="student" namespace="/student" extends="struts-default">         name="viewStudent" class="s2ex1.StudentAction" method="viewStudent">          
>   /jsp/PgStudent.jsp             
>             method="updateStudent">             name="viewStudent">/jsp/PgStudent.jsp            
>      namespace="/registration" extends="struts-default">        name="viewRegistration" class="s2ex1.RegistrationAction" 
>method="viewRegistration">            name="viewRegistration">/jsp/PgRegistration.jsp        
>        method="register">            name="viewRegistration">/jsp/PgRegistration.jsp            
>
> 2. web.xmlhttps://jakarta.ee/xml/ns/jakartaee"          
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"          
> xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee                       
>        https://jakarta.ee/xml/ns/jakartaee/web-app_5_0.xsd"          
> version="5.0">
>            struts2        
>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter
>    
>            struts2        
>/*    
>              
>  jsp/PgStudent.jsp    
>
> 3. PgRegistration.jsp<%@ taglib prefix="s" uri="/struts-tags" %>  
>   Registration Records    Registration 
> Records
>            
>    
>            
>    
> 4. PgStudent.jsp<%@ taglib prefix="s" uri="/struts-tags" %>
>     Student Info    Student - 
> Contact Information
>            
>    
>     
>           
> 5. RegistrationAction.javapackage s2ex1;
> import jakarta.servlet.http.HttpServletRequest;//import 
> jakarta.servlet.http.HttpSession;
> import org.apache.struts2.ActionSupport;import 
> org.apache.struts2.action.ServletRequestAware;
> public class RegistrationAction extends ActionSupport implements 
> ServletRequestAware {    private static final long serialVersionUID = 
> -4447001525367432296L;    private HttpServletRequest request;
>    @Override    public void withServletRequest(HttpServletRequest request) {  
>      this.request = request;    }    public HttpServletRequest 
>getWithServletRequest() {        return this.request;    }    public String 
>viewRegistration() {        return "viewRegistration";    }    public String 
>register() {        return "viewRegistration";    }    public String 
>viewStudent() {        return "viewStudent";    }}
> 6. StudentAction.javapackage s2ex1;
> import jakarta.servlet.http.HttpServletRequest;//import 
> jakarta.servlet.http.HttpSession;
> import org.apache.struts2.ActionSupport;import 
> org.apache.struts2.action.ServletRequestAware;
> public class StudentAction extends ActionSupport implements 
> ServletRequestAware {    private static final long serialVersionUID = 
> -4056538155914479859L;    private 

Re: Issue with Namespace Configuration

2025-06-10 Thread Lukasz Lenart
Is there a chance to expose source code of your app on Github? And I
would suggest learning how to use Maven to build the app instead of
Ant.

Cheers
Lukasz

pt., 6 cze 2025 o 18:49 Joseph Huynh 
napisał(a):
>
>  Hello,
> I have a simple web application to learn how the controller works in Struts 
> framework. The build is deployed to Tomcat 11.0.5. The application has two 
> simple JSP files PgStudent.jsp (configured as the welcome page) and 
> PgRegistration.jsp. Each page has two buttons to let user go back and forth 
> between the two pages. It loads the welcome page PgStudent fine, but any 
> request will encounter web error 404, like this one: There is no Action 
> mapped for namespace [/] and action name [viewRegistration] associated with 
> context path [/s2ex1], or from localhost_access log: 0:0:0:0:0:0:0:1 - - 
> [06/Jun/2025:12:12:28 -0400] "POST /s2ex1/viewRegistration HTTP/1.1" 404 829.
> Please help see where I do it wrong. Namespace is specified in JSP files, but 
> it always sees namespace as /. I am attaching the project file structure and 
> the list of the files:
> Project Files Structure
> s2ex1libcaffeine-3.1.8.jarfreemarker-2.3.34.jar
> jakarta.servlet-api-5.0.0.jar (to compile only)ognl-3.3.5.jar
> struts2-core-7.0.3.jarxwork-core-2.3.35.jarsrcs2ex1   
>  RegistrationAction.javaStudentAction.javaWebContent  
>   jspPgRegistration.jspPgStudent.jspWEB-INF   
>  struts.xmlweb.xmlbuild.xml
> List of the 7 files
> 1. struts.xml "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
> "https://struts.apache.org/dtds/struts-2.0.dtd";>  name="struts.devMode" value="true"/>   name="student" namespace="/student" extends="struts-default"> name="viewStudent" class="s2ex1.StudentAction" method="viewStudent">  
>   /jsp/PgStudent.jsp 
> method="updateStudent"> name="viewStudent">/jsp/PgStudent.jsp
>   namespace="/registration" extends="struts-default"> name="viewRegistration" class="s2ex1.RegistrationAction" 
> method="viewRegistration"> name="viewRegistration">/jsp/PgRegistration.jsp
>  method="register"> name="viewRegistration">/jsp/PgRegistration.jsp
> 
> 2. web.xmlhttps://jakarta.ee/xml/ns/jakartaee";  
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";  
> xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee   
>https://jakarta.ee/xml/ns/jakartaee/web-app_5_0.xsd";  
> version="5.0">
> struts2
> org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter
> 
> struts2
> /*
>  
> jsp/PgStudent.jsp
> 
> 3. PgRegistration.jsp<%@ taglib prefix="s" uri="/struts-tags" %>  
>   Registration RecordsRegistration 
> Records
> 
> 
> 
> 
> 4. PgStudent.jsp<%@ taglib prefix="s" uri="/struts-tags" %>
> Student InfoStudent - 
> Contact Information
> 
> 
>  method="post">
> 
> 5. RegistrationAction.javapackage s2ex1;
> import jakarta.servlet.http.HttpServletRequest;//import 
> jakarta.servlet.http.HttpSession;
> import org.apache.struts2.ActionSupport;import 
> org.apache.struts2.action.ServletRequestAware;
> public class RegistrationAction extends ActionSupport implements 
> ServletRequestAware {private static final long serialVersionUID = 
> -4447001525367432296L;private HttpServletRequest request;
> @Overridepublic void withServletRequest(HttpServletRequest request) { 
>this.request = request;} public HttpServletRequest 
> getWithServletRequest() {return this.request;} public String 
> viewRegistration() {return "viewRegistration";}public String 
> register() {return "viewRegistration";}public String 
> viewStudent() {return "viewStudent";}}
> 6. StudentAction.javapackage s2ex1;
> import jakarta.servlet.http.HttpServletRequest;//import 
> jakarta.servlet.http.HttpSession;
> import org.apache.struts2.ActionSupport;import 
> org.apache.struts2.action.ServletRequestAware;
> public class StudentAction extends ActionSupport implements 
> ServletRequestAware {private static final long serialVersionUID = 
> -4056538155914479859L;private HttpServletRequest request;
> @Overridepublic void withServletRequest(HttpServletRequest request) { 
>this.request = request;}
> public HttpServletRequest getWithServletRequest() {return 
> this.request;} public String viewStudent() {return 
> "viewStudent";}public String updateStudent() {return 
> "viewStudent";}public String viewRegistration() {return 
> "viewRegistration";}}
> 7. build.xm