【问题标题】:Action not invoked未调用操作
【发布时间】:2014-08-10 10:20:41
【问题描述】:

点击提交按钮时不会调用reg1 操作。

我的简单struts应用如下:

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 z     http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<display-name>Struts2</display-name>
<welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<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>

reg.jsp:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
 <!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=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form action="reg1" >
    Username: <input type="text" name="username"> Password: <input
        type="text" name="password"> Mobile: <input type="text"
        name="mobile"> <input type="submit" >
</form>
</body>
</html>

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="default" extends="struts-default" namespace="/">
    <action name="reg1.action" class="bean.regbean">
        <result name="success">/login.jsp</result>
    </action>
</package>
</struts>

【问题讨论】:

    标签: jsp web-applications struts2 xml-configuration


    【解决方案1】:

    未调用该操作,因为它错误地映射到表单操作属性中的 url。使用该动作配置映射动作名称,不带.action后缀使用。

    <action name="reg1" class="bean.regbean">
        <result name="success">/login.jsp</result>
    </action>
    

    另外请注意,FilterDispatcher 在最新的 Struts2 版本中已被弃用。因此,您必须相应地升级和修改web.xml。在 JSP 中,您可以使用 struts 标记将字段绑定到 bean 属性。

    【讨论】:

    • actionPackages 如果您使用 XML 配置,则不需要,OP 似乎是这样。
    • @DaveNewton 好的,那为什么是这个初始化参数呢?
    • 我假设您在谈论旧的 CodeBehind 插件的旧 actionPackages 配置参数,例如 struts.apache.org/release/2.0.x/docs/zero-configuration.html?
    • 如果这个参数与CodeBehind插件有关,为什么它在struts2过滤器的key初始化参数列表中。不推荐使用此参数的每个代码。
    • 哦,所以你不是指的是那个。基本点仍然存在:当使用 XML 配置时,显然没有必要指定任何要扫描的包,因为它们是在 XML 配置文件中明确声明的操作类。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-06
    • 1970-01-01
    • 1970-01-01
    • 2020-07-23
    • 2015-08-08
    相关资源
    最近更新 更多