读书人

MyEclipse中Struts2找不到action,该如

发布时间: 2011-12-31 23:50:30 作者: rapoo

MyEclipse中Struts2找不到action
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.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>

<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</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.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>
<package name="struts2" extends="struts-default">
<action name="helloworld" class="com.test.action.HelloWorld">
<result name="success">/helloworld.jsp</result>
</action>


<action name="login" class="com.test.action.loginAction">
<result name="success">/result.jsp</result>
</action>


</package>
</struts>

HelloWorld.java页面代码:

package com.test.action;

public class HelloWorld
{
public String execute()throws Exception
{
return "success";
}
}


helloworld.jsp页面代码:

<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%
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>
Hello World
</body>
</html>



为什么最后结果不是Hello World而是提示错误:
HTTP Status 404 - /struts2/helloworld.action

type Status report

message /struts2/helloworld.action

description The requested resource (/struts2/helloworld.action) is not available.
Apache Tomcat/6.0.30

[解决办法]
login 的访问是正常的吗? 是不是发布的问题
[解决办法]
重新部署试试,还有就是看jsp是不是放置在webRoot下面的。
------解决方案--------------------


是不是JAR包没全部倒入,是6个JAR包吗 ?
[解决办法]
一般来说,都是部署问题,要不就是action名字写错了。

读书人网 >Java相关

热点推荐