问题描述
The requested resource (There is no Action mapped for action name Sum.) is not available.下面是代码,很简单的,提示是说没这个映射,麻烦把为什么这样改说下,谢谢目录: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="Sum" class="action.FirstAction"> <result name="positive">/page/positive.jsp</result> <result name="negative">/page/negative.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"><display-name>Spec Builder</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></web-app>sum.jsp<%@ page language="java" import="java.util.*" pageEncoding="GBK" %> <%@ taglib prefix="s" uri="/struts-tags"%> <html> <head> <title>输入操作数</title> </head> <body> 求代数和 <br/> <s:form action="Sum"> <s:textfield name="operand1" label=" 操作数1"/> <s:textfield name="operand2" label=" 操作数2" /> <s:submit value="代数和" /> </s:form> </body> </html>FirstAction.javapackage 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; // 计算两个整数的代码数和 }} 问题补充:xxq 写道
解决方案
<s:form action="Sum"> 你这个URL生成没有命名空间是../Sum.action <package name="struts2" extends="struts-default"> <action name="Sum" class="action.FirstAction"> <result name="positive">/page/positive.jsp</result> <result name="negative">/page/negative.jsp</result> </action> </package>你这个要../struts2/Sum.action才能访问到吧