model.addAttribute()とrequest.setAttribute()違いは何ですか?



Model Addattribute



request.setAttribute()

このリクエストがアクションのスコープを失った後、ページ間で値を渡すと、a.jspからb.jspに渡されると、request.setAttribute()をリセットする必要があります。 (session.setAttribute()を使用すると、常にこの値がプロセスに保持されます)

注:javascriptはクライアントで実行され、jspはサーバー側で実行されるため、javascriptとjspは相互に値を渡すことはできません。それらが互いにパラメータを渡すことができるようにするには、非表示の属性コントロールjspページを設定し、それを使用して値を目的の値に渡します。



1, js to write directly in the JSP page, we are able to get to. JS pulled out if the individual is not possible to get to. The former can perhaps resolve the server to which the client can not get resolved. 2, js in the client is executed, can not directly get, because EL expressions are resolved when the server, so you can get to. A client of things, one is the server side of things. 3, jsp can get to, it is because he himself is a servlet. js not have a direct method of obtaining the attribute value HttpServletRequest inside. 4, setAttribute a server behavior to the client is invalid, but also not to mention how to use. Unless you when you wrote the jsp js variable, or use ajax request data you need.

setAttribute()のソースコードと注意事項は次のとおりです。

/** * Stores an attribute in this request. * Attributes are reset between requests. This method is most * often used in conjunction with {@link RequestDispatcher}. * *

Attribute names should follow the same conventions as * package names. Names beginning with java.*

model.addAttribute()

このメソッドとnaturerequest.setAttribute()の役割は同じで、ページ値JSPに渡すことです。



addAttribute()のソースコードと注意事項は次のとおりです。

javax.*

言及された他の記事があります、これらの2つの方法の出力値は同じではありません、参照するかもしれません:

https://blog.csdn.net/csdn1115698735/article/details/82426553



2つの設定値が同じ数ではないことも言及されている方法は参照することができます:

https://blog.csdn.net/qq_32187411/article/details/53735240