請求--攔截器--action經過

來源:互聯網
上載者:User

標籤:http   java   使用   io   ar   問題   cti   代碼   sp   

引用
我這裡想知道的是同名的多個參數,會被自動的放置在List或者數組中,我想知道是怎麼實現的,因為取一個參數和取多個同名的參數是不同的方法:
一個是request.getParameter
一個是request.getParameterValues


先解釋一下:

Struts或則XWorlk提供的Interceptor,操作的是已經被封裝好的Parameters的Map了。相信你應該看到過這句話。(在CheckboxInterceptor中有)

Java代碼 收藏代碼
Map parameters = ai.getInvocationContext().getParameters();

 

關於你的問題:

如果你說的是,同名的多個參數如何以List或者數組的方式,放在Parameter的Map中。

這個應該是屬於Servlet規範中的內容。在HTTP協議的Request傳遞到ServletContainer中後,Container就會為該次請求產生一個HTTPServletRequest對象,在HTTPServletRequest對象中,參數和值,放入到了Map中。

在Tomcat的實現代碼中,可以看到,同名的參數的值,被加入的String數組中。單個的參數,也是放在數組中的。
Java代碼 收藏代碼

/**
* Put name and value pair in map. When name already exist, add value
* to array of values.
*
* @param map The map to populate
* @param name The parameter name
* @param value The parameter value
*/
private static void putMapEntry( Map map, String name, String value) {
String[] newValues = null;
String[] oldValues = (String[]) map.get(name);
if (oldValues == null) {
newValues = new String[1];
newValues[0] = value;
} else {
newValues = new String[oldValues.length + 1];
System.arraycopy(oldValues, 0, newValues, 0, oldValues.length);
newValues[oldValues.length] = value;
}
map.put(name, newValues);
}


引用
因為取一個參數和取多個同名的參數是不同的方法:
一個是request.getParameter
一個是request.getParameterValues

都可以使用request.getParameterValues的方法,通過迴圈來得到值、或者賦值。


如果你說的是,同名的多個參數如何以List或者數組的方式,放在Action中。

那就需要看Struts的OGNL實現的源碼,Interceptor只是將值轉移到ValueStatck上,而後由ONGL進行賦值的。


總結:你在Interceptor中是看不到你期望的判斷語句的。因為,封裝的判斷語句在Servlet的容器中實現;解鎖裝的語句,在struts2的OGNL中實現。Interceptor只是對其中值,稍微做些處理

請求--攔截器--action經過

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.