问题
I have tried everything to run my first Struts2 demo application but i am failed to run it. I have followed the tutorial on
http://www.quickprogrammingtips.com/struts2/struts-2-netbeans-tutorial.html
Here is my web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app 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"
version="3.1">
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<display-name>Struts2 Demo App</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>
Here is my struts.xml
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="Struts2Demo" extends="struts-default">
<action name="HelloWorld" class="controller.HelloWorld">
<result>/message.jsp</result>
</action>
<!-- Add your actions here -->
</package>
</struts>
here is controller file
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package controller;
import com.opensymphony.xwork2.ActionSupport;
import model.Message;
public class HelloWorld extends ActionSupport {
private Message message;
@Override
public String execute() {
setMessage(new Message()); // get data from model
return SUCCESS;
}
public Message getMessage() {
return message;
}
public void setMessage(Message message) {
this.message = message;
}
}
Here is my jsp file
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="Struts2Demo" extends="struts-default">
<action name="HelloWorld" class="controller.HelloWorld">
<result>/message.jsp</result>
</action>
<!-- Add your actions here -->
</package>
</struts>
and here is the model file
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package model;
public class Message {
private String message = "Hello World!";
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
}
My file structure is
Netbeans version: 8.1 Glassfish server: 4 All struts2 configuration are setup manually without any plugin
回答1:
Your startup logs indicate precisely what the problem is, although you'll run into more of the same, since you're not deploying all the required dependencies.
At a minimum, for your app, you need:
WEB-INF/lib
├── commons-fileupload-1.3.1.jar
├── commons-io-2.2.jar
├── 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.6.jar
├── struts2-core-2.3.24.1.jar
└── xwork-core-2.3.24.1.jar
This is why you should be using Maven, Gradle, or an equivalent dependency manager. Each library used by a Java application has its own dependencies, and you are missing a lot of them.
I used http://mvnrepository.com/ to manually grab the libraries your app requires, using startup error messages as a guide. This is a skill you should acquire even though it's managed for you by Maven/etc. Without knowing what all it handles you'll be tempted to think you don't need it.
来源:https://stackoverflow.com/questions/32911439/struts2-confgured-in-netbeans-8-returning-http-status-404-not-found