在地址栏输入:http://localhost:8090/struts2/test/helloworld.action
浏览器报错如下:
HTTP Status 404 - /struts2/WEB-INF/page/hello.jsp
--------------------------------------------------------------------------------
type Status report
message /struts2/WEB-INF/page/hello.jsp
description The requested resource (/struts2/WEB-INF/page/hello.jsp) is not available.
--------------------------------------------------------------------------------
Apache Tomcat/6.0.33
在web项目中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>index.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>*.action</url-pattern>
</filter-mapping></web-app>
struts.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<package name = "itcast" namespace="/test" extends="struts-default">
<action name="helloworld" class="action.HelloWorldAction.helloworld" method="execute">
<result name="success">/WEB-INF/page/hello.jsp</result>
</action>
</package>
</struts>
action.HelloWorldAction文件下的helloworld.java文件
package action.HelloWorldAction;
public class helloworld {
String message = "";
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public String execute(){
message="我的第一个struts2应用";
return "success";
}
}
/WEB-INF/page/下的helloworld.jsp文件
<%@ page language="java" import="java.util.*" pageEncoding="gb2312"%>
<%
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 JSP 'helloworld.jsp' starting page</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>
This is my JSP page. <br>
${message}
</body>
</html>
各位大侠 求问题出的原因。(照着黎活明老师的我的第一个struts2视屏做的)用的myeclipse8.6。里面用的struts2文件包为myeclipse自带的。
|