读书人

一个简单的web例子。如何也无法运行

发布时间: 2013-06-25 23:45:42 作者: rapoo

一个简单的web例子。怎么也无法运行
web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>Ex_Struts20</display-name>
<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>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
</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" namespace="/mystruts"
extends="struts-default">
<action name="sum" class="action.FirstAction">
<result name="positive">/positive.jsp</result>
<result name="negative">/negative.jsp</result>
</action>
</package>
</struts>

sum.jsp
<%@ page language="java" import="java.util.*" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<html>
<head>
<title>sum</title>
</head>
<body>
please add them!
<br/>
<s:form action="mystruts/sum.action" >
<s:textfield name="operand1" label="Data1"/>
<s:textfield name="operand2" label="Data2"/>
<s:submit value="add"/>
</s:form>
</body>
</html>

positive.jsp
<%@ page language="java" import="java.util.*" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>


<title>Insert title here</title>
</head>
<body>
result is <h1><s:property value="sum" /></h1>
</body>
</html>

negative.jsp
<%@ page language="java" import="java.util.*" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
<title>Insert title here</title>
</head>
<body>
result is <h1><s:property value="sum" /></h1>
</body>
</html>

tomcat的sever.xml里追加
<Context path="/struts2" docBase="E:/workspace/Ex_Struts20/WebContent" />

http://localhost:8080/struts2/sum.jsp运行ok。
但是输入数字后,提交就报错。
There is no Action mapped for action name sum.
The requested resource is not available.


请大神指教并告诉我怎么修改。。。

[解决办法]

引用:
Quote: 引用:

我QQ392190627. 直接发我,给你改。

兄弟,我没法用qq。有邮箱么?
- -。QQ邮箱撒。392190627@qq.com。。这么简单。。

读书人网 >Java Web开发

热点推荐