I'm trying to follow this tutorial about how getting started to Struts. I followed the exact steps, but in the end I got this error HTTP Status 404 - /Struts2-HelloWorldExample/
I know 404 error means that I was able to communicate to the server, but server could not find what I requested. I suspected that there's something wrong with my library, but I couldn't find anything in the solution for the same problem.
My java code:
package com.aziz;
public class HelloWorldExample {
private String name;
public String execute() throws Exception {
return "success";
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
<display-name>Struts 2 - Hello World Example</display-name>
<welcome-file-list>
<welcome-file>index.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>
hello.jsp:
<%@taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html>
<html>
<head>
<title>Hello World Example</title>
</head>
<body>
Hello <s:property value="name"/>!
</body>
</html>
index.jsp:
<!DOCTYPE html>
<html>
<head>
<title>Hello World Example</title>
</head>
<body>
<h1>Hello World Example</h1>
<form action="hello">
<label for="name">Enter your name</label><br/>
<input type="text" name="name"/>
<input type="submit" value="Submit"/>
</form>
</body>
</html>
struts.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<constant name="struts.devMode" value="true" />
<package name="default" namespace="/" extends="struts-default">
<action name="hello"
class="com.aziz.HelloWorldExample">
<result name="success">hello.jsp</result>
</action>
</package>
</struts>
And I'm not sure what i'm doing is right or wrong but i just added manually struts library that i've downloaded from here (full distribution) in the WEB-INF/lib folder, so I have these JAR in that folder:
And the last thing, I have no error but these warning on my markers:
I already checked this error, Idk what's that mean because when I see the solution, someone say i need to decide whether and which of the libraries to copy to the WAR in project Properties -> Java EE Module Dependencies. But in my project properties there's no such thing as Java EE Module Dependencies. I really need your help. Thanks in advance.
Make sure that you have put the jsp files inside WEBCONTENT not in WEB-INF and try to put only the libraries which I have given below.
commons-collections-3.1.jar, commons-fileupload-1.3.1.jar, commons-io-2.2.jar, commons-lang-2.4.ja,r commons-lang3-3.2.jar, commons-logging-1.1.3.jar, freemarker-2.3.22.jar, javassist-3.11.0.GA.jar, ognl-3.0.13.jar, struts2-core-2.3.28.jar, xwork-core-2.3.28.jar,
Try this and try restarting the server and check it.Hope it works.
Regards, Dhanya
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.