新建web项目的一个菜鸟问题
我用myeclipsie8.5新建了一个web项目,用来做一个最简单的sturts2的例子,但是一直是报错,找了好几天没找到原因,你知道的帮忙解决下谢了。我是新手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.enable.DynamicMethodInvocation" value="false" />
<constant name="struts.devMode" value="false" />
<include file="example.xml"/>
<package name="default" namespace="/" extends="struts-default">
<default-action-ref name="index" />
<action name="index">
<result type="redirectAction">
<param name="actionName">HelloWorld</param>
<param name="namespace">/example</param>
</result>
</action>
</package>
-->
<constant name="struts.devMode" value="true" />
<package name="default" namespace="/" extends="struts-default">
<action name="hell">
<result>
/Hello.jsp
</result>
</action>
</package>
<!-- Add packages here -->
</struts>
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">
<welcome-file-list>
<welcome-file>hello.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>
hello.jsp--
<%@ page language="java" import="java.util.*" pageEncoding="GB18030"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My first struts</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
struts2!! <br>
</body>
</html>
我输入http://localhost:8080/Struts2_0101_Introduction/hell报错如下:
HTTP Status 404 - /Struts2_0101_Introduction/Hello.jsp
--------------------------------------------------------------------------------
type Status report
message /Struts2_0101_Introduction/Hello.jsp
description The requested resource (/Struts2_0101_Introduction/Hello.jsp) is not available.
--------------------------------------------------------------------------------
Apache Tomcat/6.0.33
知道的请回答一下,加我QQ也可以:183741440
--------------------编程问答-------------------- 我也出现这个问题了,一直没有解决。期待高手回答。 --------------------编程问答-------------------- 文件名没对应上吧 --------------------编程问答-------------------- 配置里是 Hello.jsp
你的文件名是不是写成了 hello.jsp? --------------------编程问答-------------------- 文件名是hello.jsp,对应上的 --------------------编程问答-------------------- 你配置里写的是Hello.jsp
<constant name="struts.devMode" value="true" />--------------------编程问答-------------------- 我改回来了还是不行,直接访问http://localhost:8080/Struts2_0101_Introduction/hello.jsp还是报错 --------------------编程问答-------------------- 上面你那样访问当然不行,因为你没有设置action。
<package name="default" namespace="/" extends="struts-default">
<action name="hell">
<result>
/Hello.jsp
</result>
</action>
</package>
<!-- Add packages here -->
</struts>
应该这样访问:http://localhost:8080/Struts2_0101_Introduction/hell
试一下吧 --------------------编程问答-------------------- 不行的,试过了。跟版本什么的有关系吗 --------------------编程问答-------------------- 有错误信息吗?把控制台的信息贴出来,最好先重启一下tomcat --------------------编程问答-------------------- 没有信息啊控制台里,有时间的话QQ联系帮忙看下啊,兄弟 --------------------编程问答-------------------- 812992918
补充:Java , Eclipse