Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | ||||
| 4 | 5 | 6 | 7 | 8 | 9 | 10 |
| 11 | 12 | 13 | 14 | 15 | 16 | 17 |
| 18 | 19 | 20 | 21 | 22 | 23 | 24 |
| 25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- NetBeans
- File
- jquery
- CentOS
- junit
- error
- java
- MySQL
- laravel
- Android
- JSON
- larravel
- properties
- DB
- html
- ajax
- php
- SeLinux
- curl
- 이클립스
- Spring
- input
- 와일드카드
- 리눅스
- 안드로이드
- Linux
- 정규식
- 톰캣
- javascript
- tomcat
Archives
- Today
- Total
합쭈기 programming
request parameter를 서버단에서 추가하기 본문
filter단에서 request parameter에 기본적으로 셋팅하고 싶은 정보가 있을때 사용한다.
AddParamHttpRequest.java
public class AddParamHttpRequest extends HttpServletRequestWrapper {
private final Map modifiableParameters;
private Map allParameters = null;
/**
* Create a new request wrapper that will merge additional parameters into
* the request object without prematurely reading parameters from the
* original request.
*
* @param request
* @param additionalParams
*/
public AddParamHttpRequest(final HttpServletRequest request,
final Map additionalParams) {
super(request);
modifiableParameters = new TreeMap();
modifiableParameters.putAll(additionalParams);
}
@Override
public String getParameter(final String name) {
String[] strings = getParameterMap().get(name);
if (strings != null) {
return strings[0];
}
return super.getParameter(name);
}
@Override
public Map getParameterMap() {
if (allParameters == null) {
allParameters = new TreeMap();
allParameters.putAll(super.getParameterMap());
allParameters.putAll(modifiableParameters);
}
// Return an unmodifiable collection because we need to uphold the
// interface contract.
return Collections.unmodifiableMap(allParameters);
}
@Override
public Enumeration getParameterNames() {
return Collections.enumeration(getParameterMap().keySet());
}
@Override
public String[] getParameterValues(final String name) {
return getParameterMap().get(name);
}
}
'Java > Spring' 카테고리의 다른 글
| out of memory 체크 (0) | 2015.05.06 |
|---|---|
| filter에서 bean 사용하기 (0) | 2015.04.27 |
| junit test 셋팅 (0) | 2015.04.27 |
| tomcat 원격 deploy (0) | 2015.04.27 |
| 강제 locale 설정 (0) | 2015.04.27 |