首页 新闻 会员 周边

大神求救!struts2定义多个action的问题

0
悬赏园豆:50 [待解决问题]

问题:当点击aa的时候,可以成功跳转到success.jsp页面,但是点击bb的时候则报错,这是问什么呢?

下面是我测试的struts.xml、web.xml、index.jsp的文件代码

struts.xml文件

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
    "http://struts.apache.org/dtds/struts-2.3.dtd">

<struts>

    <constant name="struts.enable.DynamicMethodInvocation" value="false" />
    <constant name="struts.devMode" value="true" />

    <package name="default" namespace="/" extends="struts-default">

        <action name="aa">
            <result>/success.jsp</result>
        </action>
        
        <action name="bb">
            <result>/success.jsp</result>
        </action>
             
    </package>
</struts>


web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_9" 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.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
    </filter>

<filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
index.jsp

<%@taglib prefix="s" uri="/struts-tags" %>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
    <a href="aa.action">aa</a><br>
    <a href="bb.action">bb</a>
</body>
</html>

问题:当点击aa的时候,可以成功跳转到success.jsp页面,但是点击bb的时候则报错,这是问什么呢?

错误信息如下:

  • There is no Action mapped for namespace [/] and action name [bb] associated with context path [/tetsstruts].
wyTT的主页 wyTT | 初学一级 | 园豆:104
提问于:2015-08-20 13:48
< >
分享
所有回答(1)
0

我的猜测是(希望可以帮到你):从你的aa,可以点击,说明你的配置没有错误,aa调用了你的默认控制器,但是你bb,还是没有指定地址,将不会再调默认的控制器了,就报出了找不到控制器的错误,对于 dispatcher -   forward运用服务器跳转  服务器跳转    显示action   redirect   -   重定向一般才这么写

<struts>  
    <constant name="struts.devMode" value="true" />  
    <package name="resultTypes" namespace="/r" extends="struts-default">  
        <action name="r1">  
            <result type="dispatcher">/r1.jsp</result>  
        </action>  
          
        <action name="r2">  
            <result type="redirect">/r2.jsp</result>  
        </action>  
          
        <action name="r3">  
            <result type="chain">r1</result>  
        </action>  
          
        <action name="r4">  
            <result type="redirectAction">r2</result>  
        </action>  
          
    </package>  
</struts>  

你这种模拟Struts1中的ForwardAction连续2个会报错的

             <action name="user">

       <result>/index.jsp</result>

              </action>

稳稳的河 | 园豆:4216 (老鸟四级) | 2015-08-21 11:05
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册