我正在嘗試學習Struts2,但我無法創建工作的Hello World應用程序。當從JSP發出請求時,它會發出404(頁面未找到)錯誤。我把所有的lib文件都放在了lib文件夾中,放在classes文件夾下面的struts.xml
,但是我仍然收到這個錯誤。從JSP發出請求時發生404錯誤
這裏是視圖:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Hello World</title>
</head>
<body>
<form action="HelloWorld">
<input type="submit">
</form>
</body>
</html>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<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>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</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="default" extends="struts-default">
<action name="HelloWorld" class="vaannila.HelloWorld">
<result name="SUCCESS">/success.jsp</result>
</action>
</package>
</struts>
這是錯誤:
HTTP Status 404 - /Testi/HelloWorld
type Status report
message /Testi/HelloWorld
description The requested resource (/Testi/HelloWorld) is not available.
Apache Tomcat/6.0.33
你怎麼做呢?您是否使用Eclipse IDE並將tomcat添加爲服務器?第一個html/jsp代碼的文件名是什麼 – Jayy
這可能是因爲它沒有定位你的struts.xml,或者在啓動期間發生了一些其他錯誤,導致無法加載Struts2。 –