根据文档,我可以使用includeContext = "false"
来避免实际的上下文应该包含在URL中。
当我使用这一行时:
<s:a action="persist" namespace="books" includeParams="get" includeContext="false" cssClass="btn btn-xs btn-success">
<s:text name="actions.books.edit" />
<s:param name="idBook"><s:property value="id" /></s:param>
</s:a>
生成的网址为:
http://localhost:8080/ejercicio4-web/books/books/persist.action?idBook=6
成为当前网址:
http://localhost:8080/ejercicio4-web/books/all.action
如果我使用<s:url>
组件,如果它正常工作:
http://localhost:8080/ejercicio4-web/books/persist.action?idBook=6
struts.xml完成配置:
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<constant name="struts.enable.DynamicMethodInvocation" value="false"/>
<constant name="struts.devMode" value="true"/>
<!-- Use Guice as the ObjectFactory for this application -->
<constant name="struts.objectFactory" value="guice" />
<constant name="struts.custom.i18n.resources" value="global" />
<constant name="struts.url.includeParams" value="get" />
<!-- Default App Package -->
<package name="app-default" abstract="true" extends="struts-default, tiles-default">
<interceptors>
<interceptor name="saveParamsOnSession" class="interceptors.SaveParamsOnSession"/>
<interceptor-stack name="secure">
<interceptor-ref name="roles">
<param name="allowedRoles">ADMIN</param>
</interceptor-ref>
<interceptor-ref name="paramsPrepareParamsStack"/>
</interceptor-stack>
<interceptor-stack name="storeFlashDataStack">
<interceptor-ref name="store">
<param name="operationMode">STORE</param>
</interceptor-ref>
<interceptor-ref name="defaultStack" />
</interceptor-stack>
<interceptor-stack name="storeParamsPrepareParamsStack">
<interceptor-ref name="store">
<param name="operationMode">STORE</param>
</interceptor-ref>
<interceptor-ref name="paramsPrepareParamsStack" />
<interceptor-ref name="saveParamsOnSession" />
</interceptor-stack>
</interceptors>
<global-results>
<result name="ejbexception" type="tiles">app.error.ejbexception</result>
</global-results>
<global-exception-mappings>
<exception-mapping exception="javax.ejb.EJBException" result="ejbexception" />
</global-exception-mappings>
</package>
<!-- Books package -->
<package name="books" namespace="/books" extends="app-default">
<!--<default-interceptor-ref name="secure"/>-->
<default-action-ref name="home" />
<action name="home" class="actions.BaseAction">
<result type="tiles">app.books.home</result>
</action>
<!-- persist book -->
<action name="persist" class="actions.books.PersistBookAction">
<interceptor-ref name="store">
<param name="operationMode">RETRIEVE</param>
</interceptor-ref>
<interceptor-ref name="servletConfig" />
<interceptor-ref name="params" />
<interceptor-ref name="prepare" />
<result type="tiles">app.books.persist</result>
</action>
<action name="proccess" class="actions.books.PersistBookAction" method="proccess">
<interceptor-ref name="storeParamsPrepareParamsStack" />
<interceptor-ref name="fileUpload">
<param name="allowedTypes">application/pdf</param>
</interceptor-ref>
<exception-mapping exception="java.io.IOException" result="input" />
<result name="input" type="redirectAction">persist.action?idBook=${book.id}</result>
<result type="redirectAction">persist.action?idBook=${book.id}</result>
</action>
<!-- Show Book -->
<action name="show" class="actions.books.BookAction">
<interceptor-ref name="paramsPrepareParamsStack" />
<result type="tiles">app.books.show</result>
</action>
<action name="pdf" class="actions.books.ShowPDFAction">
<interceptor-ref name="basicStack" />
<result name="success" type="stream">
<param name="contentType">application/pdf</param>
<param name="inputName">inputStream</param>
<param name="contentDisposition">inline;filename="test.pdf"</param>
<param name="bufferSize">1024</param>
</result>
</action>
<!-- Remove book -->
<action name="remove" class="actions.books.RemoveBookAction">
<interceptor-ref name="store">
<param name="operationMode">STORE</param>
</interceptor-ref>
<interceptor-ref name="paramsPrepareParamsStack" />
<result name="input" type="redirectAction">all</result>
<result type="redirectAction">all</result>
</action>
<!-- Books list -->
<action name="all" class="actions.books.BooksAction">
<interceptor-ref name="storeParamsPrepareParamsStack" />
<result type="tiles">app.books.all</result>
</action>
</package>
<!-- Authors package -->
<package name="authors" namespace="/authors" extends="app-default">
<action name="create" class="actions.authors.CreateAuthorAction">
<interceptor-ref name="storeFlashDataStack" />
<result name="input" type="redirectAction">books/persist</result>
<result type="redirectAction">
<param name="actionName">persist</param>
<param name="namespace">/books</param>
</result>
</action>
</package>
<!-- Accounts package -->
<package name="accounts" namespace="/accounts" extends="app-default">
<action name="login" class="actions.accounts.SigninAction">
<interceptor-ref name="store">
<param name="operationMode">RETRIEVE</param>
</interceptor-ref>
<result>/WEB-INF/views/accounts/login.jsp</result>
</action>
<action name="check" class="actions.accounts.SigninAction" method="check">
<interceptor-ref name="store">
<param name="operationMode">STORE</param>
</interceptor-ref>
<result name="input" type="redirectAction">login</result>
<result type="redirectAction">login</result>
</action>
<action name="signup" class="actions.accounts.PreCreateUserAction">
<interceptor-ref name="store">
<param name="operationMode">RETRIEVE</param>
</interceptor-ref>
<result type="tiles">app.accounts.signup</result>
<result name="input" type="tiles">app.accounts.signup</result>
</action>
<action name="create" class="actions.accounts.PostCreateUserAction">
<interceptor-ref name="store">
<param name="operationMode">STORE</param>
</interceptor-ref>
<interceptor-ref name="fileUpload">
<param name="allowedTypes">image/jpeg,image/jpg,image/png</param>
</interceptor-ref>
<interceptor-ref name="defaultStack" />
<result name="input" type="redirectAction">signup</result>
<result type="redirectAction">signup</result>
</action>
</package>
</struts>
我做错了什么?
答案 0 :(得分:1)
为什么使用includeContext
属性?你应该删除它
<s:a action="persist" namespace="books" cssClass="btn btn-xs btn-success">
<s:text name="actions.books.edit" />
<s:param name="idBook"><s:property value="id" /></s:param>
</s:a>
框架正在使用UrlHelper
为所有标记生成网址,因此无法预测您如何使用生成的代码。 includeContext
是Boolean
属性,表示
“是否应在URL中包含实际上下文”
创建HTML的标记。此标记支持相同的属性 作为“url”标记,包括使用“param”标记的嵌套参数。
另外你为什么使用includeParams="get"
?网址中只有一个参数。