java - Struts 2 简单成功页面不直接指向 SampleAction 类

标签 java jsp struts2 action-mapping

我已按照 youtube 中的教程进行操作通过关于struts,我完全遵循了每一步,但我有一个问题,我的程序没有引导我去上课。我知道它不会定向,因为它没有显示消息 System.out.println("from execute");

这是我的代码:

<强> struts.xml :

<?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="sample" class="com.struts.sample.action.SampleAction">
            <result name="success">/success.jsp</result>
            <result name="error">/error.jsp</result>
        </action>
    </package>    
</struts>

<强> web.xml :

<?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>Struts2Example</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.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>

<强> SampleAction.java :

package com.struts.sample.action;

public class SampleAction {

    public String execute(){

        System.out.println("from execute");
        return "success";
    }

}

<强> success.jsp :

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

我得到这个输出:

HTTP Status 404 - There is no Action mapped for namespace [/] and action name [getTutorial] associated with context path [/Struts2Example].
<小时/>

类型状态报告:

message There is no Action mapped for namespace [/] and action name [getTutorial] associated with context path [/Struts2Example].

description The requested resource is not available.

这是我的控制台:

Dec 13, 2013 11:40:46 AM org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jre7\bin;C:\windows\Sun\Java\bin;C:\windows\system32;C:\windows;C:\Program Files\Broadcom\Broadcom 802.11 Network Adapter\Driver;;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\windows\system32;C:\windows;C:\windows\System32\Wbem;C:\windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Intel\OpenCL SDK\2.0\bin\x86;C:\Program Files (x86)\Intel\OpenCL SDK\2.0\bin\x64;C:\Program Files\Lenovo\Bluetooth Software\;C:\Program Files\Lenovo\Bluetooth Software\syswow64;C:\Program Files\Lenovo Fingerprint Reader\;C:\Program Files\Lenovo Fingerprint Reader\x86\;C:\ProgramData\Lenovo\ReadyApps;C:\Program Files\TortoiseSVN\bin;.
Dec 13, 2013 11:40:47 AM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:Struts2Example' did not find a matching property.
Dec 13, 2013 11:40:47 AM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8080"]
Dec 13, 2013 11:40:47 AM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-bio-8009"]
Dec 13, 2013 11:40:47 AM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 733 ms
Dec 13, 2013 11:40:47 AM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Dec 13, 2013 11:40:47 AM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.42
log4j:WARN No appenders could be found for logger (com.opensymphony.xwork2.util.fs.DefaultFileManagerFactory).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Dec 13, 2013 11:40:48 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8080"]
Dec 13, 2013 11:40:48 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-bio-8009"]
Dec 13, 2013 11:40:48 AM org.apache.catalina.startup.Catalina start
INFO: Server startup in 1711 ms

因为这个 System.out.println("from execute"); 控制台中应该有类似“fromexecute”的内容但它不会进入类 我不知道如何调试它了。 enter image description here

最佳答案

您的WEB-INF/class 应重命名为WEB-INF/classes。在包资源管理器中右键单击文件夹名称并选择重命名或重构/重命名。如果这不起作用,请打开资源透视图并重命名文件夹名称。之后清理、重建并重新部署项目。

关于java - Struts 2 简单成功页面不直接指向 SampleAction 类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20558617/

相关文章:

已部署 Java struts 应用程序但拒绝启动

java - 如何在java中分割电子邮件ID

java - 在我的项目中使用 JAVA 实现 Elasticsearch 的最佳方法是什么?

java - 无法在eclipse中导入jsp页面中的类

javascript - 无法计算文本字段值

java - Struts 2 选择带有数组列表值的标签

java - JPA注释映射与hibernate,以及最佳关系模型

java - launch4j maven 插件 - 配置 .exe 以需要管理员角色

jsp - Java EE 错误 : javax. enterprise.inject.UnsatisfiedResolutionException:Api 类型

spring - JSP页面无法在spring boot embedded undertow上显示