【发布时间】:2015-10-02 16:13:01
【问题描述】:
我已经尝试了一切来运行我的第一个 Struts2 演示应用程序,但我无法运行它。我已按照
上的教程进行操作http://www.quickprogrammingtips.com/struts2/struts-2-netbeans-tutorial.html
这是我的 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>
这是我的 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>
这里是控制器文件
/*
* 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;
}
}
这是我的jsp文件
<!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>
这是模型文件
/*
* 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;
}
}
我的文件结构是
Netbeans 版本:8.1 Glassfish 服务器:4 所有 struts2 配置都是手动设置的 没有任何插件
【问题讨论】:
-
您尝试了哪些其他 URL?你试过JDK 7吗?
-
它是一个非常小的 URL 子集,而你却错过了一个巨大的。
-
如果您能指导我,我将不胜感激,这是我尝试在 netbeans 上运行的第一个项目,我没有使用 struts2 的经验,我尝试过的所有示例都给了我同样的错误。我正在使用 JDK 7
-
首先您需要构建部署工件或
.war文件以部署在服务器上,然后您需要检查它是否已部署在指定上下文/Struts2Demo。将index.html文件放到根目录下,看看是否有效。
标签: jsp netbeans struts2 netbeans-8 build-dependencies