description The requested resource (/struts2/hello.action) is not available.
能访问index.jsp文件,但是提交时却出现上述错误,都检查好几天了,都没有解决这个问题,希望各位大虾们能帮帮我这个菜鸟啊~~,感激不尽啊源代码如下:
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="mldn" namespace="/" extends="struts-default">
<action name="hello" class="org.lxh.struts2.demo.HelloAction">
<result name="success">
/hello.jsp
</result>
<result name="error">
/error.jsp
</result>
</action>
</package>
</struts>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>hello.jsp</welcome-file>
</welcome-file-list>
</web-app>
helloworld.java
package org.lxh.struts2.demo;
import com.opensymphony.xwork2.ActionSupport;
public class HelloAction extends ActionSupport {
private String msg="Hello World" ;
public String getMsg() {
return ActionSupport.SUCCESS ;
}
public void setMsg(String msg) {
System.out.println("**********************");
this.msg = msg;
}
@Override
public String execute() throws Exception {
if("mldnlxh".equalsIgnoreCase(this.msg)){
return ActionSupport.SUCCESS;
}else{
return ActionSupport.ERROR;
}
}
}
hello.jsp
<%@ page language="java" import="java.util.*" pageEncoding="GBK"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
<title>My JSP 'hello.jsp' starting page</title>
</head>
<body>
<s:property value="msg"/>
</body>
</html>
index.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<html>
<head>
<title>My JSP 'index.jsp' starting page</title>
</head>
<body>
<form action="hello.action" method="post">
请输入内容:<input type="text" name="msg">
<input type="submit" value="提交">
</form>
</body>
</html>
errors.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 'errors.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>
</body>
</html>
--------------------编程问答-------------------- 你的struts.xml配置文件怎么不贴出来
form action="hello.action"
现在没有地方去hello.action 然后就报错
你的struts.xml中应该有name 为 hello.action的<action /> 配置 --------------------编程问答-------------------- 我觉得这个问题可能是由于楼主没有将类org.lxh.struts2.demo.HelloAction编译后的Class文件部署到web-inf/class目录下造成的。其他的配置我没有看出什么问题哈
补充:Java , Web 开发