能访问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
<?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>
解决方案 »
- 人员可见的问题
- 动态树形菜单实现!
- servlet程序哪里错了啊?谢谢~
- 关于struts的一个问题
- jsp新手有关文件上传及组件问题...达人帮帮忙啊
- 求一个原创的有源码的JAVA制作的XML转换小工具(报酬具体谈)
- 如何在struts中根据actionform的值来设定jsp中的radio选中状态
- 求助:连接池问题! 感谢高手了!
- 寻找一个会Apache + PHP + MySQL的朋友帮忙~
- xmvigour、beyond_xiruo 2位板主,以解决的问题怎么有很多连接打不开呀?
- hibernate 删除的问题...............
- illegal type archive fro erquired library
form action="hello.action"
现在没有地方去hello.action 然后就报错
你的struts.xml中应该有name 为 hello.action的<action /> 配置