How to pass a list from one action to another in Struts 2 without using session?

前端 未结 2 1142
庸人自扰
庸人自扰 2020-12-11 09:17

I am displaying a list in my JSP as shown below:

<%@page  contentType=\"text/html;charset=UTF-8\"language=\"java\"pageEncoding=\"UTF-8\"%>
<%@taglib         


        
2条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-11 09:46

    The reason your code isn't working is because

    
    

    Doesn't do what you think it does.

    This sets a hidden field on the HTML page called propagateList to the value of formList.toString(). This is obviously not useful.

    You need to set is as CSV or JSON or some serialized from and then deserialize it when is sent back by the client.

    There seems to be client/sever side confusion.

    First you get the formlist from the db and use it to render your page. This is an HTML page, it is sent to the client.

    The client renders the HTML with your formList and the does something, clicks add for example.

    The result of the add is that the client sends a POST request back to the server with the data.

    Do you really think it is more efficient to send 1000 values back to the server in serialized from and then deserialize them back into a List rather than hit the db? For one thing it means that a POST request which should be very small becomes rather large.

    Use a Session or maybe cache it locally in some sort of static cache.

提交回复
热议问题