java - HTTP 404 错误 - 在简单的 Struts2 应用程序中

标签 java eclipse tomcat struts2 http-status-code-404

一个简单的 hello world 应用程序显示 http-404 错误。

我正在使用以下工具:

1) eclipse Luna 4.4

2) Apcache tomcat 7.0

3) JDK 7


应用结构

My application structure looks like this

我是否遗漏了任何 jar 文件???

index.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>Simple form</title>
</head>
<body>
<form action="Myaction" method="get">
<input type="text" name="t1"><br>
<input type="submit" value="GO">
</form>
</body>
</html>

Myaction.java

package com.Action;

public class Myaction {
String t1;

public String getT1(){
    return t1;
}
public void setT1(String t1) {
    this.t1 = t1;
}
public String execute(){
    System.out.println(t1);
    return "success";
}
}

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="default" extends="struts-default">

    <action name="Myaction" class="com.Action.Myaction" method="execute">
        <result name="success" type="redirect">/Welcome.jsp</result>
    </action>
</package>
</struts>

欢迎.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib uri="/struts-tags" prefix="s" %>    
<!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>Welcome | Home</title>
</head>
<body>
<label>Welcome -> <s:property value="t1"/> </label>
</body>
</html>

enter image description here

显示此警告的标记

<s:property> -- 在构建路径中找不到

此外,服务器显示错误:资源不可用 如何解决这个错误?

谢谢

最佳答案

解决方案是:

在网络项目中

1) 进入Build Path-配置构建路径

2) 如果你使用的是外部 JRE 那么它会给出 Http 404 错误,所以我使用了 JDK 即添加库- Libraries- Installed JREs

3) 给出JDK的路径。 (我们必须使用内部 JRE)

4)完成

5) 刷新项目

它会起作用..

关于java - HTTP 404 错误 - 在简单的 Struts2 应用程序中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30002656/

相关文章:

java - Spring MVC 窗体 :options tag not wiring into my objects Id?

android - 无法在 Eclipse Juno Mac 中安装新软件

java - 带有 Netbeans 7.3 的 Tomcat 7 不记录

java - 如何从另一个 Apache 服务器查找 Apache 服务器是否正在运行?

Java树节点选择

java - Jackrabbit Lucene 索引

java - java FileOutputStream write 方法 (int)

python - Eclipse 控制台中的 Pydev 源文件超链接

java - 如何更改 Eclipse OSGi Framework Launcher 使用的 OSGi Launcher Jar

tomcat - 从 WEB-INF/lib/*.jar!/META-INF/resources 间歇加载