JSP 面接 族譜 整理 (3日次)
1. JSP / Servlet에서 한글處理方式은?
- Tomcat 서버의 基本文字 處理方式은 ISO 8859 1 方式이기 때문에 開發者가 別途의 한글 인코딩을 하지 않으면 디폴트로 ISO 8859 1로 잡혀서 한글이 깨져 보이는 現象이 생긴다。
- 2種類의 方式의 處理方法이 있다。Get方式(서버)과 Post方式(Servlet)
- 하지만 서버는 건들지 않는 것이 좋다!Servlet 파일을 修正하자。
- UTF-8 (유니코드)을 使用하자。
2. 下段의 JSP 태그를 說明하시오。
3. 九々段을 세로로 나타내도록 JSP로 作成하시오。
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<h2>九々段</h2>
<table border="1">
<tr>
<%
for (int i = 2; i < 10; i++) {
out.print("<th>" + i + "段</th>");
}
%>
</tr>
<%
for (int i = 1; i < 10; i++) {
%>
<tr>
<%
for (int j = 2; j < 10; j++) {
out.print("<td align=center>" + j + " x " + i + " = " + (i * j) + "</td>");
}
%>
</tr>
<%
}
%>
</table>
</body>
</html>
4. 國英數 總點과 平均을 웹上에서 나오도록 作成하시오。
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<form action="grade" method="post">
國語 : <input type="text" name="kor" size="10"><br>
英語 : <input type="text" name="eng" size="10"><br>
數學 : <input type="text" name="math" size="10"><br>
<input type="submit" value="傳送">
<input type="reset" value="初期化">
</form>
</body>
</html>
public class Grade {
private int kor;
private int eng;
private int math;
public Grade(int kor, int eng, int math) {
this.kor = kor;
this.eng = eng;
this.math = math;
}
public int getKor() {
return kor;
}
public void setKor(int kor) {
this.kor = kor;
}
public int getEng() {
return eng;
}
public void setEng(int eng) {
this.eng = eng;
}
public int getMath() {
return math;
}
public void setMath(int math) {
this.math = math;
}
public int getSum() {
return kor + eng + math;
}
public double getAvg() {
return getSum() / 3.0;
}
}