NetBeans 8中配置的Struts2返回HTTP状态404-找不到 [英] Struts2 confgured in netbeans 8 returning HTTP Status 404 - Not Found

查看:124
本文介绍了NetBeans 8中配置的Struts2返回HTTP状态404-找不到的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经尽一切努力来运行我的第一个Struts2演示应用程序,但是我无法运行它.我已按照

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

这是我的web.xml

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>

这是我的struts.xml

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>

这是控制器文件

    /*
 * 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配置都是手动设置的 没有任何插件

Netbeans version: 8.1 Glassfish server: 4 All struts2 configuration are setup manually without any plugin

推荐答案

您的启动日志准确地指出了问题所在,尽管由于您没有部署所有必需的依赖项,您也会遇到更多类似的问题.

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

这就是为什么您应该使用Maven,Gradle或等效的依赖项管理器的原因. Java应用程序使用的每个库都有其 own 依赖项,您会丢失很多依赖项.

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.

我使用启动错误消息,使用 http://mvnrepository.com/手动获取应用程序所需的库作为指导.即使由Maven/etc管理,这也是您应该掌握的一项技能.不知道它处理的是什么,您会以为自己不需要它.

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.

这篇关于NetBeans 8中配置的Struts2返回HTTP状态404-找不到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆