关于struts2框架中的“There is no Action mapped for namespace /a and action name toform.”这个错误的原因

这个问题的造成原因是:struts.xml配置文件中的package标签的namespace属性'/b'和在网址栏输入'http://shna4w8081nqyz5:8080/Struts2/a/toform.action'的不同,正确的输入是'http://shna4w8081nqyz5:8080/Struts2/b/toform.action'这样。
在struts.xml文件中的配置
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
	<package name="a" namespace="/b" extends="struts-default">
<action name="checked" class="com.action.TextAction" method="text">
			<result name="success">/index.jsp</result>
		</action>
		<action name="toform">
			<result>/index01.jsp</result>
		</action>
	</package>
</struts>    
在index.jsp页面中
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
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 'index.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>
   <form action="a/logo.action" method="post">
   	<table>
   		<tr>
   			<td>账户:</td>
   			<td><input type="text" name="name"/></td>
   		</tr>
   		<tr>
   			<td>密码:</td>
   			<td><input type="password" name="password"/></td>
   		</tr>
   		<tr>
   			<td><input type="submit" value="登录"/></td>
   			<td><input type="reset" value="重置"/></td>
   		</tr>
   	</table>
   </form>
   <a href="a/shiwu.action">error.jsp</a>
  </body>
</html>
在index01.jsp页面中
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'index.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>
  <% 
  List<String> country=new ArrayList<String>();
  country.add("美国");
  country.add("中国");
  country.add("法国");
  country.add("英国");
  country.add("俄罗斯");
  request.setAttribute("countrys", country);
  %>
   <s:form action="checked" method="post">
   <s:textfield name="name"></s:textfield>
   <s:password name="password"></s:password>
   <s:radio name="country1" list="#request.countrys"></s:radio>
   <s:select name="country2" list="#request.countrys"></s:select>
   <s:submit value="提交"></s:submit>
   </s:form>
  </body>
</html>


在TextAction类中
package com.action;

public class TextAction {
	
	String name;
	String password;
	String country1;
	String country2;
	public String text(){
		System.out.println("已用text()方法");
		System.out.println(name);
		System.out.println(password);
		System.out.println(country1);
		System.out.println(country2);
		return "success";
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public String getCountry1() {
		return country1;
	}
	public void setCountry1(String country1) {
		this.country1 = country1;
	}
	public String getCountry2() {
		return country2;
	}
	public void setCountry2(String country2) {
		this.country2 = country2;
	}
	
}


在package com.action;


public class TextAction {
	
	String name;
	String password;
	String country1;
	String country2;
	public String text(){
		System.out.println("已用text()方法");
		System.out.println(name);
		System.out.println(password);
		System.out.println(country1);
		System.out.println(country2);
		return "success";
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public String getCountry1() {
		return country1;
	}
	public void setCountry1(String country1) {
		this.country1 = country1;
	}
	public String getCountry2() {
		return country2;
	}
	public void setCountry2(String country2) {
		this.country2 = country2;
	}
	
}
在TestAction类中:
package com.action;

public class TestAction {
	 String name;
	 String password;
		
	public String execute(){
		System.out.println("接收到请求");
		System.out.println("name:"+name+",password:"+password);
	    return "success";
	       
	}
	
	public String test(){
		System.out.println("发送错误的请求");
		return "error";
	}
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}
	
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值