我想使用struts2构建一个Web应用程序并将我的网页部署在服务器上。
我从Youtube上的教程开始。 链接。
并且我收到错误为 原始服务器找不到目标资源的当前表示,或者不愿意透露其存在。
我使用Java版本8 带有Eclipse版本2019-03 我的运行时服务器是Apache Tomcat v9.0。 操作系统是Windows 10。
教程链接: https://www.youtube.com/watch?v=f46WEeM8HTA&list=PLB7BB551126EDD5E0
我写的代码如下:
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>
<package name="Struts2.1" extends="struts-default" >
<action name="getTutorial" class="org.yat.javabrains.action.TutorialAction">
<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://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd" id="WebApp_ID" version="4.0">
<display-name>Struts2.1</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>
TutorialAction.java
package org.yat.javabrains.action;
public class TutorialAction {
public String execute()
{
String success="success";
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>Struts2 tutorial</title>
</head>
<body bgColor="lightblue">
Hello world!!!This is Struts 2 tutorial
</body>
</html>
error.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>
Error!!!!
</body>
</html>
im getting the output as
[enter image description here][1]
The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.
Could someone please tell me what is going wrong.
I intially thought it to be an error due to some struts jar error.
I've tried with the srtuts(v2.5.20, v2.3.27,v2.3.30)
but all gave the same error.
[1]: https://i.stack.imgur.com/jXL7n.jpg