为什么s:action不是每次都执行?
Why s:action did not be executed every time?
在 JSP 页面中,我使用 s:action 来调用操作。
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<!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>online shop market</title>
</head>
<body>
<h1>welcome</h1>
<s:action name="listallAction" executeResult="true" />
</body>
</html>
这是我的 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.devMode" value="true" />
<package name="default" namespace="/" extends="struts-default">
<action name="loginAction" class="action.CustomerAction" method="login">
<result name="SUCCESSLOGIN">/welcome.jsp</result>
</action>
<action name="listallAction" class="action.ItemAction" method="listall">
<result name="SUCCESSLISTALL">/allitems.jsp</result>
</action>
</package>
</struts>
为了便于理解,我在这里保存了一些代码。
我的问题是:第一种情况,在做loginAction的时候,登录成功后,会映射到这个页面,调用listallAction。 listallAction实现成功,内容包含在该页面中。我看到 URL 是 http://localhost:8080/XXProject/loginAction. In the second situation, after launching the tomcat, in the browser, I just called the welcome.jsp page, the url is http://localhost:8080/XXProject/welcome.jsp。这次,它没有执行s:action!服务器告诉我:没有为操作名称 listallAction 映射的操作。 - [未知位置]。这个问题与 url 路径有关吗?我在谷歌上搜索了一些关于 url 路径的信息,但对它感到更加困惑。
让我自己回答,有点冷.....我在s:action标签中添加了namespace="/"。它成功了!只是想知道为什么 s:action 没有在 XML 文件中的包中添加命名空间。
在 JSP 页面中,我使用 s:action 来调用操作。
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<!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>online shop market</title>
</head>
<body>
<h1>welcome</h1>
<s:action name="listallAction" executeResult="true" />
</body>
</html>
这是我的 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.devMode" value="true" />
<package name="default" namespace="/" extends="struts-default">
<action name="loginAction" class="action.CustomerAction" method="login">
<result name="SUCCESSLOGIN">/welcome.jsp</result>
</action>
<action name="listallAction" class="action.ItemAction" method="listall">
<result name="SUCCESSLISTALL">/allitems.jsp</result>
</action>
</package>
</struts>
为了便于理解,我在这里保存了一些代码。 我的问题是:第一种情况,在做loginAction的时候,登录成功后,会映射到这个页面,调用listallAction。 listallAction实现成功,内容包含在该页面中。我看到 URL 是 http://localhost:8080/XXProject/loginAction. In the second situation, after launching the tomcat, in the browser, I just called the welcome.jsp page, the url is http://localhost:8080/XXProject/welcome.jsp。这次,它没有执行s:action!服务器告诉我:没有为操作名称 listallAction 映射的操作。 - [未知位置]。这个问题与 url 路径有关吗?我在谷歌上搜索了一些关于 url 路径的信息,但对它感到更加困惑。
让我自己回答,有点冷.....我在s:action标签中添加了namespace="/"。它成功了!只是想知道为什么 s:action 没有在 XML 文件中的包中添加命名空间。