Multiple result types in Struts2?

柔情痞子 提交于 2019-12-04 05:29:02

问题


I have a Struts2 application where I using Tiles. How can I get multiple result types in action-mappings? because I need to set de output as JSON data, and Tiles simultaneous. I have tried:

<action
    name="home"
    class="com.deveto.struts.actions.HomeAction" >
    <result name="success" type="tiles,json">tiles.home</result>
</action>

But this isn't working


回答1:


To my knowledge there is no way to return multiple things simultaneously. The browser will only be expecting one thing, either the JSON or the HTML once all the tiles stuff is done.

I can think of two ways to do this: double request (one for each result type) or use one to generate the other (get the JSON and use JavaScript to construct the HTML on the client).

What are you trying to accomplish that you need both results?




回答2:


create a new result type for Tiles+JSON & use it... you can't define 2 result types in a result tag.




回答3:


How about if u have 2 diff results?!

<result name="successJSON" type="json"/>

<result name="successTiles" type="tiles">tiles.home</result>

then in your server code u just route to the right one?!



来源:https://stackoverflow.com/questions/6456007/multiple-result-types-in-struts2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!