ドキュメントによれば、私はincludeContext = "false"
を使用して実際のコンテキストをURLに含めるべきではないということを避けることができます。includeContContext on <s:a> struts2タグが機能しない
私はこのライン使用時:
<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>
を生成したURLはこれです:
http://localhost:8080/ejercicio4-web/books/books/persist.action?idBook=6
は、現在のURLビーイング:
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>
私が間違っているのでしょうか?
''タグに 'namespace'属性を使用しました。 –
私はnamespace属性を使用する必要があります。でも私はそれを使用しても問題ありません –
どちらのS2バージョンですか?あなたのパッケージの名前空間は何ですか? '
'を試してください。 –