提交后就报这个错:The requested resource (There is no Action mapped for action name Sum.)
The requested resource (There is no Action mapped for action name Sum.) is not available.
下面是代码,很简单的,提示是说没这个映射,麻烦把为什么这样改说下,谢谢
目录:
[img]http://dl.iteye.com/upload/attachment/537165/b3d62be5-0cbd-3cf4-a7e2-aaf56e543c79.jpg[/img]
struts.xml
[code="java"]<?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">
/page/positive.jsp
/page/negative.jsp
[/code]
web.xml
[code="java"]<?xml version="1.0" encoding="UTF-8"?>
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">
Spec Builder
struts2
org.apache.struts2.dispatcher.FilterDispatcher
struts2
/*
[/code]
sum.jsp
[code="java"]<%@ page language="java" import="java.util.*" pageEncoding="GBK" %>
<%@ taglib prefix="s" uri="/struts-tags"%>
输入操作数
<body>
求代数和
<br/>
<s:form action="Sum">
<s:textfield name="operand1" label=" 操作数1"/>
<s:textfield name="operand2" label=" 操作数2" />
<s:submit value="代数和" />
</s:form>
</body>
[/code]
FirstAction.java
[code="java"]package action;
import com.opensymphony.xwork2.ActionSupport;
public class FirstAction extends ActionSupport
{
private int operand1;
private int operand2;
public String execute() throws Exception
{
if (getSum() >= 0) // 如果代码数和是非负整数,跳到positive.jsp页面
{
return "positive";
}
else // 如果代码数和是负整数,跳到negative.jsp页面
{
return "negative";
}
}
public int getOperand1()
{
return operand1;
}
public void setOperand1(int operand1)
{
System.out.println(operand1);
this.operand1 = operand1;
}
public int getOperand2()
{
return operand2;
}
public void setOperand2(int operand2)
{
System.out.println(operand2);
this.operand2 = operand2;
}
public int getSum()
{
return operand1 + operand2; // 计算两个整数的代码数和
}
}
[/code]
你这个URL生成没有命名空间是../Sum.action
/page/positive.jsp
/page/negative.jsp
你这个要../struts2/Sum.action才能访问到吧