1

I have followed a tutorial in youtube by about struts I completely followed every step but I have a problem my program doesn't direct me to the class. I know that it doesn't direct because it does not show the message System.out.println("from execute");

Here is my code:

struts.xml:

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

<struts>
    <package name="default" extends="struts-default">
        <action name="sample" class="com.struts.sample.action.SampleAction">
            <result name="success">/success.jsp</result>
            <result name="error">/error.jsp</result>
        </action>
    </package>    
</struts>

web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>Struts2Example</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>

    <filter>
        <filter-name>struts2</filter-name>
        <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
    </filter>

    <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>  
</web-app>

SampleAction.java:

package com.struts.sample.action;

public class SampleAction {

    public String execute(){

        System.out.println("from execute");
        return "success";
    }

}

success.jsp:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!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=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
success
</body>
</html>

I'm getting this output:

HTTP Status 404 - There is no Action mapped for namespace [/] and action name [getTutorial] associated with context path [/Struts2Example].

Type Status report:

message There is no Action mapped for namespace [/] and action name [getTutorial] associated with context path [/Struts2Example].

description The requested resource is not available.

This is my console:

Dec 13, 2013 11:40:46 AM org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jre7\bin;C:\windows\Sun\Java\bin;C:\windows\system32;C:\windows;C:\Program Files\Broadcom\Broadcom 802.11 Network Adapter\Driver;;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\windows\system32;C:\windows;C:\windows\System32\Wbem;C:\windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Intel\OpenCL SDK\2.0\bin\x86;C:\Program Files (x86)\Intel\OpenCL SDK\2.0\bin\x64;C:\Program Files\Lenovo\Bluetooth Software\;C:\Program Files\Lenovo\Bluetooth Software\syswow64;C:\Program Files\Lenovo Fingerprint Reader\;C:\Program Files\Lenovo Fingerprint Reader\x86\;C:\ProgramData\Lenovo\ReadyApps;C:\Program Files\TortoiseSVN\bin;.
Dec 13, 2013 11:40:47 AM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:Struts2Example' did not find a matching property.
Dec 13, 2013 11:40:47 AM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8080"]
Dec 13, 2013 11:40:47 AM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-bio-8009"]
Dec 13, 2013 11:40:47 AM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 733 ms
Dec 13, 2013 11:40:47 AM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Dec 13, 2013 11:40:47 AM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.42
log4j:WARN No appenders could be found for logger (com.opensymphony.xwork2.util.fs.DefaultFileManagerFactory).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Dec 13, 2013 11:40:48 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8080"]
Dec 13, 2013 11:40:48 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-bio-8009"]
Dec 13, 2013 11:40:48 AM org.apache.catalina.startup.Catalina start
INFO: Server startup in 1711 ms

There should be something like "from execute" in the console because of this System.out.println("from execute"); but it does not go in the class I don't know how to debug it anymore. enter image description here

Roman C
  • 49,761
  • 33
  • 66
  • 176
  • What is the project structure of your application? – Roman C Dec 13 '13 at 04:56
  • when the value of return is "success" i will run the success.jsp is this what your asking me..the problem is that from struts.xml im not directed to the SampleAction.java which means i cant return the value "success" and i cant run the page success any ideas on this?i've tried several suggestion on other pages but they wont work on my problem like this one here http://stackoverflow.com/questions/7776969/there-is-no-action-mapped-for-namespace-and-action-name-helloworld –  Dec 13 '13 at 05:00
  • I asked you what is the folder and files structure, also how the build is made. Are you using maven for build process or other? – Roman C Dec 13 '13 at 05:04
  • i added the photo by the way the folder WEB-INF/class/struts.xml is a suggestion i forgot to take it i added it to try if it works but it didn't i still get the same out put. and i'm using struts 2 i hope im being clear here so you can understand my problem –  Dec 13 '13 at 05:21
  • the name of the output path should be WEB-INF/classes and the project output better map to this folder. If it's not the same then it should be assembled to copy project output there at the build time. – Roman C Dec 13 '13 at 05:25
  • i cant understand that one but can you tell me in steps what i need to do? –  Dec 13 '13 at 05:33

2 Answers2

0

You have WEB-INF/class should be renamed to WEB-INF/classes. In the the package explorer right click on the folder name and choose rename or refactor/rename. If this doesn't work open a resource perspective and rename the folder name. After that clean and rebuild and redeploy the project.

Roman C
  • 49,761
  • 33
  • 66
  • 176
  • sample result HTTP Status 404 - There is no Action mapped for namespace [/] and action name [sample] associated with context path [/Struts2Example]. –  Dec 13 '13 at 05:50
  • the action name should be `sample` not `getTutorial` it should correspond that you have written yourself in `struts.xml` and that is different in your picture. – Roman C Dec 13 '13 at 05:55
  • i changed it already.the code was a bit late i already change that one but same result.i only change it to geTutorial because that was the one in tutorial but im using sample in my code and sample when im running –  Dec 13 '13 at 06:02
  • Is what you running correspond that you have configured? – Roman C Dec 13 '13 at 06:07
  • please check the changes not really that much but sample result what do you think is the reason for this –  Dec 13 '13 at 06:24
  • After this change I don't see where the `struts.xml` is. – Roman C Dec 13 '13 at 06:40
  • sorry didnt expand on it but i follow your suggestion, i put it here WEB-INF/classes still same output i tried doing this http://localhost:8080/Struts2Example/success.jsp and the success page was the result so i think i cant go into SampleAction.java plus i cant see the system.out.println in console so im not going inside the class.. i also tried putting sample only without .action same result –  Dec 13 '13 at 06:44
0

what i did was to delete the saved jar in WEB-INF/lib i think my problems was because i had double jar one from the tutorial way and the other was because i had paste the same jar in the said folder.jar redundant my have cause my problem so if you have done the same delete the saved jar and rerun the program it will work for sure