1

I'm learning struts 2 from Java Brains. I've written a simple Hello world type struts 2 web application. It just shows an success page or error page. I've done everything instructed in the tutorial, but unfortunately the page is not loading. Following is the project explorer.

enter image description here

I've edited web.xml file like below.

<?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>Struts 2 Web Application</display-name>
    <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>

According to the tutorial, above web.xml configuration handovers the whole request response process to struts. I've configured struts.xml file like following.

<?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="getTutorial" class="action.TutorialAction">
            <result name="success">/success.jsp</result>
            <result name="failure">/error.jsp</result>
        </action>
    </package>
</struts>

I've written action.TutorialAction class like following.

package action;

public class TutorialAction {
    public String execute(){
        System.out.println("Hello From execute");
        return "success";
    }
}

After running the project under Tomcat 7, the url "http://localhost:8080/Struts2Starter/getTutorial.action" should load success.jsp page. But it's showing 404 error.

success.jsp page is just a .jsp page.

<%@ 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 Page
</body>
</html>

I'm clueless why it's not running. I've been banging my head to solve it for a week and at last it just no hope :( . Help me please, Thanks in advance.

Rafaf Tahsin
  • 7,652
  • 4
  • 28
  • 45

4 Answers4

1

Please see the following points carefully:

1) You must add all the jar files of struts2 which is easily avaliable on "javatpoint".

2) Run it with only getTutorial instead of getTutorial.action, like "http://localhost:8080/Struts2Starter/getTutorial" sometimes its work.

Hope its will work for you.

Sahil
  • 78
  • 1
  • 12
  • what is javatpoint? I've included all the jars of struts 2. As they are a lot, I didn't include them in the project explorer pic. I tried both http://localhost:8080/Struts2Starter/getTutorial and "http://localhost:8080/Struts2Starter/getTutorial.action , neither one works. – Rafaf Tahsin Jul 06 '15 at 05:27
  • Javatpoint is a website where you get tutorials of java, sorry for the incomplete information. You can check the link http://www.javatpoint.com/ – Sahil Jul 06 '15 at 08:56
  • Thanks for your suggestion, I'll go through the site. Anyway, are you on struts 2 too? I saw you asked http://stackoverflow.com/questions/30252470/eclipse-not-validating-the-struts-xml-file this question on may. – Rafaf Tahsin Jul 06 '15 at 09:00
  • Yeah i am on struts2 too, Meanwhile i am trying to solve your query asap. – Sahil Jul 06 '15 at 09:22
  • 1
    @Rafaf Your code is working fine, There will be no error from my side but just be ensure that you are using the dtd version in struts.xml file according to your version of jar files added. – Sahil Jul 06 '15 at 10:57
  • I think there's some configuration problem in my eclipse ... I'm using eclipse luna, jre7, tomcat 7, struts 2.3.24. – Rafaf Tahsin Jul 06 '15 at 11:50
  • 1
    I don't think its an eclipse issue if your other projects runs fine. Try to find the problem more accurately and try to clean the project from eclipse at every updation in project. – Sahil Jul 06 '15 at 12:15
0

Java Brains uses struts 2 Version 2.3.1.1. But the version of struts used in this project is 2.3.24. These two versions conflict. The project runs successfully using version 2.3.1.1. You can download struts 2.3.1.1 or any other older version of struts from here.

Rafaf Tahsin
  • 7,652
  • 4
  • 28
  • 45
0

same problem-I downloaded struts-2.3.2 which is the oldest version in struts2 provided in the link http://archive.apache.org/dist/struts/ but still comes error 404-not found with the above specified urls i.e http://localhost:8080/Struts2Starter/getTutorial and http://localhost:8080/Struts2Starter/getTutorial.action both.

0

Please see the following points carefully:

1) You must add all the jar files of struts2 which is easily avaliable on "javatpoint".

2) Run it with only getTutorial instead of getTutorial.action, like "http://localhost:8080/Struts2Starter/getTutorial" sometimes its work. You can also watch Java video's from here https://www.youtube.com/channel/UCWJ9QB_Ng-dgEOFd_1Ouobg