1

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>
4

1 回答 1

2

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

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

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

于 2014-08-10T13:07:04.710 回答