簡體   English   中英

找不到Struts2.3資源

[英]Struts2.3 resource not found

這是我在Struts的第一個項目。 當我運行這個項目時,我收到錯誤:

"The requested resource is not available." 

這就是我所做的:

我正在使用Struts 2.3.15。 這就是我的項目結構: 項目結構

這是index.jsp頁面:

   <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
   pageEncoding="ISO-8859-1"%>
   <%@ taglib prefix="s" uri="/struts-tags"%>
   <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
   "http://www.w3.org/TR/html4/loose.dtd">
   <html>
   <head>
      <title>Hello World</title>
   </head>
   <body>
      <h1>Hello World From Struts2</h1>
   <form action="hello">
    <label for="name">Please enter your name</label><br/>
    <input type="text" name="name"/>
    <input type="submit" value="Say Hello"/>
   </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="helloworld" extends="struts-default">
      <action name="hello" 
       class="com.tutorialspoint.struts2.HelloWorldAction" 
       method="execute">
       <result name="success">/HelloWorld.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" 
 xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
 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>Struts 2</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.FilterDispatcher
  </filter-class>
</filter>
<filter-mapping>
   <filter-name>struts2</filter-name>
   <url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>

這是HelloWorld.jsp

<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
<title>Hello World</title> 
</head>
 <body>
   Hello World, <s:property value="name"/>
 </body>
</html>

這是HelloWorldAction.jsp

package com.tutorialspoint.struts2;
public class HelloWorldAction{
private String name;
  public String execute() throws Exception {
     return "success";
  }
  public String getName() {
    return name;
  }

  public void setName(String name) {
    this.name = name;
  }
}

我做的另一件事是我將從提取的struts文件夾中粘貼的所有庫復制到WEB-INF/lib文件夾。

我錯過了什么,這里有什么問題?

我想我已經解決了你的問題,你需要將它添加到配置文件struts.xml ,當運行你的web應用程序時,它應該在classpath上。

<action name="index">
    <result>/index.jsp</result>
</action>

嘗試

http://localhost:8080/HelloWorldStruts2/index.action

請刪除堆棧跟蹤,這不是你的問題的答案,所以你不應該把它作為答案,你得到這個錯誤的原因是,你有太多的罐子被復制到'WWE-INF / lib',只是刪除你不需要的所有插件,有類似的問題: 類似的問題 ,它也可能是你的解決方案

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM