반응형
반응형

[JSTL] Tag가 jsp 화면에 그대로 노출될 경우, escapeXml  

JSTL로  처리를 할 때, 태그가 적용이 안되고 화면에 그대로 노출이 될 때가 있다.

기본적으로 escapeXml 이라는 값이 true로 처리가 되고, 이 속성은 <, > 와 같은 값들을 <, > 등으로 변경하여 화면에 뿌려주게 된다.

하지만, 태그를 원하는 대로 뿌려줘야 할 경우도 존재하니 이럴 경우 escapeXml="false" 처리를 해주면 된다.

<c:out value="${값}" />
<c:out value="${값}" escapeXml="false" />
 
반응형
반응형

[JSTL] 한자리 숫자 앞에 0붙이기, addZero

<c:forEach var="c" items="${contents.content}" varStatus="status">
    <fmt:formatNumber var="no" minIntegerDigits="2" value="${status.count}" type="number"/>
     ${no}
</c:forEach>
반응형
반응형

[JAVA] HttpURLConnection로 REST API 호출하기 

public void post(String strUrl, String jsonMessage){
		try {
			URL url = new URL(strUrl);
			HttpURLConnection con = (HttpURLConnection) url.openConnection();
			con.setConnectTimeout(5000); //서버에 연결되는 Timeout 시간 설정
			con.setReadTimeout(5000); // InputStream 읽어 오는 Timeout 시간 설정
			con.addRequestProperty("x-api-key", RestTestCommon.API_KEY); //key값 설정

			con.setRequestMethod("POST");

            //json으로 message를 전달하고자 할 때 
			con.setRequestProperty("Content-Type", "application/json");
			con.setDoInput(true);  // InputStream으로 응답 헤더와 메시지를 읽어들이겠다는 옵션
			con.setDoOutput(true); //POST 데이터를 OutputStream으로 넘겨 주겠다는 설정 
			con.setUseCaches(false);
			con.setDefaultUseCaches(false);

			OutputStreamWriter wr = new OutputStreamWriter(con.getOutputStream());
			wr.write(jsonMessage); //json 형식의 message 전달 
			wr.flush();

			StringBuilder sb = new StringBuilder();
			if (con.getResponseCode() == HttpURLConnection.HTTP_OK) {
				//Stream을 처리해줘야 하는 귀찮음이 있음.
				BufferedReader br = new BufferedReader(
						new InputStreamReader(con.getInputStream(), "utf-8"));
				String line;
				while ((line = br.readLine()) != null) {
					sb.append(line).append("\n");
				}
				br.close();
				System.out.println("" + sb.toString());
			} else {
				System.out.println(con.getResponseMessage());
			}
		} catch (Exception e){
			System.err.println(e.toString());
		}
}

 

// 요청할 파라미터의 정보를 입력한다.
String body = "id=asdf&pass=asdf";

// URL클래스의 생성자로 주소를 넘겨준다.
URL u = new URL( 주소 );

// 해당 주소의 페이지로 접속을 하고, 단일 HTTP 접속을 하기위해 캐스트한다.
HttpURLConnection  huc = (HttpURLConnection) u.openConnection();

// POST방식으로 요청한다.( 기본값은 GET )
huc.setRequestMethod("POST");

//InputStream으로 응답 헤더와 메시지를 읽어들이겠다는 옵션을 정의한다.
   huc.setDoInput(true);

// OutputStream으로 POST 데이터를 넘겨주겠다는 옵션을 정의한다.
   huc.setDoOutput(true);

// 요청 헤더를 정의한다.( 원래 Content-Length값을 넘겨주어야하는데 넘겨주지 않아도 되는것이 이상하다. )
   huc.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");

// 새로운 OutputStream에 요청할 OutputStream을 넣는다.
   OutputStream os = huc.getOutputStream();

// 그리고 write메소드로 메시지로 작성된 파라미터정보를 바이트단위로 "EUC-KR"로 인코딩해서 요청한다.

// 여기서 중요한 점은 "UTF-8"로 해도 되는데 한글일 경우는 "EUC-KR"로 인코딩해야만 한글이 제대로 전달된다.
   os.write( body.getBytes("euc-kr") );

// 그리고 스트림의 버퍼를 비워준다.
   os.flush();

// 스트림을 닫는다.
os.close();

// 응답받은 메시지의 길이만큼 버퍼를 생성하여 읽어들이고, "EUC-KR"로 디코딩해서 읽어들인다.
BufferedReader br = new BufferedReader( new OutputStreamReader( huc.getInputStream(), "EUC-KR" ), huc.getContentLength() );

String buf;

// 표준출력으로 한 라인씩 출력
while( ( buf = br.readLine() ) != null ) {
    System.out.println( buf );
}

// 스트림을 닫는다.
br.close();

 

반응형
반응형

[JSTL core] [c:forEach] varStatus를 활용한 변수

forEach문은 아래와 같이 활용한다.

<c:foreach items="${리스트가 받아올 배열이름}"
           var="for문 내부에서 사용할 변수"
           varStatus="상태용 변수">

	// 반복해서 표시할 내용 혹은 반복할 구문

</c:foreach>

이 때, 상태용 변수를 status라고 지정했다면 아래와 같이 활용할 수 있다.

 

${status.current} 현재 for문의 해당하는 번호

${status.index} 0부터의 순서

${status.count} 1부터의 순서

${status.first} 첫 번째인지 여부

${status.last} 마지막인지 여부

${status.begin} for문의 시작 번호

${status.end} for문의 끝 번호

${status.step} for문의 증가값

<c:foreach items="${list}" var="list" varStatus="status">
	<c:out value="${status.index}" /> / <c:out value="${status.end}" />
</c:foreach>
반응형
반응형

Hide the navigation bar - Android

https://developer.android.com/training/system-ui/navigation#behind

 

Hide the navigation bar  |  Android Developers

This lesson describes how to hide the navigation bar, which was introduced in Android 4.0 (API level 14). Even though this lesson focuses on hiding the navigation bar, you should design your app to hide the status bar at the same time, as described in Hidi

developer.android.com

This lesson describes how to hide the navigation bar, which was introduced in Android 4.0 (API level 14).

Even though this lesson focuses on hiding the navigation bar, you should design your app to hide the status bar at the same time, as described in Hiding the Status Bar. Hiding the navigation and status bars (while still keeping them readily accessible) lets the content use the entire display space, thereby providing a more immersive user experience.

You can hide the navigation bar using the SYSTEM_UI_FLAG_HIDE_NAVIGATION flag. This snippet hides both the navigation bar and the status bar:

View decorView = getWindow().getDecorView();
// Hide both the navigation bar and the status bar.
// SYSTEM_UI_FLAG_FULLSCREEN is only available on Android 4.1 and higher, but as
// a general rule, you should design your app to hide the status bar whenever you
// hide the navigation bar.
int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
              | View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);
반응형
반응형

jsp 현재 날짜, 일주일전 날짜, 한달 전 날짜 구하기.

currentCalendar.add 부분에 -값이 아닌 +값을 대입하면 현재 이후의 날짜를 구할 수 있지요.

 

<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page import="java.text.DecimalFormat" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="java.util.Calendar" %>

<%
    DecimalFormat df = new DecimalFormat("00");
    Calendar currentCalendar = Calendar.getInstance();

  //현재 날짜 구하기
    String strYear   = Integer.toString(currentCalendar.get(Calendar.YEAR));
    String strMonth  = df.format(currentCalendar.get(Calendar.MONTH) + 1);
    String strDay   = df.format(currentCalendar.get(Calendar.DATE));
    String strDate = strYear + strMonth + strDay;

  //일주일 전 날짜 구하기
    currentCalendar.add(currentCalendar.DATE, -7);
    String strYear7   = Integer.toString(currentCalendar.get(Calendar.YEAR));
    String strMonth7  = df.format(currentCalendar.get(Calendar.MONTH) + 1);
    String strDay7   = df.format(currentCalendar.get(Calendar.DATE));
    String strDate7 = strYear7 + strMonth7 + strDay7;

  //한달 전 날짜 구하기
    currentCalendar.add(currentCalendar.DATE, -24);
    String strYear31   = Integer.toString(currentCalendar.get(Calendar.YEAR));
    String strMonth31  = df.format(currentCalendar.get(Calendar.MONTH) + 1);
    String strDay31   = df.format(currentCalendar.get(Calendar.DATE));
    String strDate31 = strYear31 + strMonth31 + strDay31;
%>

<!-- 현재날짜 -->
<c:set var="nowdate" value='<%=strDate%>' />
<!-- 일주일전 -->
<c:set var="nowdate7" value='<%=strDate7%>' />
<!-- 한달전 -->
<c:set var="nowdate31" value='<%=strDate31%>' /> 
반응형

+ Recent posts