본문 바로가기

노트필기

[Web] JSPClass0720-1

JSP Class0720-1



[html]


<!DOCTYPE html>

<html>

<head>

<meta charset="EUC-KR">

<title>Insert title here</title>

</head>

<body>

<form action="ex10" method="get">

<input type="text" name="num1"> 

<select name="method">

<option>+</option>

<option>-</option>

<option>*</option>

<option>/</option>

</select>

<input type="text" name="num2">

<input type="submit" value="계산">

</form>

</body>

</html>


[JAVA]

package com.example;


import java.io.IOException;

import java.io.PrintWriter;


import javax.servlet.ServletException;

import javax.servlet.annotation.WebServlet;

import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;


/**

 * Servlet implementation class ex10

 */

@WebServlet("/ex10")

public class ex10 extends HttpServlet {

protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

String method = request.getParameter("method");

int num_1 = Integer.parseInt(request.getParameter("num1"));

int num_2 = Integer.parseInt(request.getParameter("num2"));

double result = 0;

response.setContentType("text/html");

PrintWriter out = response.getWriter();

result = calculate(method, num_1, num_2, result);

if (method.equals("/")) {

out.print(num_1 + method + num_2 + " = " + result);

} else {

out.print(num_1 + method + num_2 + " = " + (int)result);

}

}


private double calculate(String method, int num_1, int num_2, double result) {

switch (method) {

case "+":

result = num_1 + num_2;

break;

case "-":

result = num_1 - num_2;

break;

case "*":

result = num_1 * num_2;

break;

case "/":

result = (double)num_1 / num_2;

break;

default:

break;

}

return result;

}


}




============================================
* page지시자 (형식 : <%@ %>)



============================================
[JSP-1]

<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>Insert title here</title>
</head>
<body>
<form action="ex09Request.jsp" method="post">
<fieldset>
<legend>학점확인프로그램</legend>
<table>
<tr>
<td>이름</td>
<td><input type="text" name="name"></td>
</tr>
<tr>
<td>JAVA점수</td>
<td><input type="text" name="java"></td>
</tr>
<tr>
<td>Web점수</td>
<td><input type="text" name="web"></td>
</tr>
<tr>
<td>IOT점수</td>
<td><input type="text" name="iot"></td>
</tr>
<tr>
<td>ANDROID점수</td>
<td><input type="text" name="android"></td>
</tr>
<tr>
<td colspan="2"><input type="submit" value="확인하기!!"></td>
</tr>
</table>
</fieldset>
</form>
</body>
</html>

[JSP-2]

<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>Insert title here</title>
</head>
<body>
<%
request.setCharacterEncoding("euc-kr");
String name = request.getParameter("name");
int java = Integer.parseInt(request.getParameter("java"));
int web = Integer.parseInt(request.getParameter("web"));
int iot = Integer.parseInt(request.getParameter("iot"));
int android = Integer.parseInt(request.getParameter("android"));
double avg = (double)((int)((java + web + android + iot) / 4 * 10)) / 10;

String grade = "";
if (avg >= 95) {
grade = "A+";
} else if (avg >= 85) {
grade = "A";
} else if (avg >= 80) {
grade = "B+";
} else if (avg >= 70) {
grade = "C";
} else {
grade = "F";
}
%>

<fieldset>
<legend>학점확인프로그램</legend>
<table>
<tr>
<td>이름</td>
<td><%=name%></td>
</tr>
<tr>
<td>JAVA점수</td>
<td><%=java%></td>
</tr>
<tr>
<td>Web점수</td>
<td><%=web%></td>
</tr>
<tr>
<td>IOT점수</td>
<td><%=iot%></td>
</tr>
<tr>
<td>ANDROID점수</td>
<td><%=android%></td>
</tr>
<tr>
<td>평균</td>
<td><%=avg%></td>
</tr>
<tr>
<td>학점</td>
<td><h1><%=grade%></h1></td>
</tr>
</table>
</fieldset>

</body>
</html>




============================================
[HTML]

<!DOCTYPE html>
<html>
<head>
<meta charset="EUC-KR">
<title>Insert title here</title>
</head>
<body>
<form action="ex12URL.jsp" method="post">
<select name="url">
<option>네이버</option>
<option>다음</option>
<option>구글</option>
</select>
<input type="submit" value="이동">
</form>
</body>
</html>

[JSP]
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>Insert title here</title>
</head>
<body>
<%
request.setCharacterEncoding("euc-kr");
String url = request.getParameter("url");
if(url.equals("네이버")) {
response.sendRedirect("https://www.naver.com");
} else if(url.equals("다음")) {
response.sendRedirect("http://www.daum.net");
} else if(url.equals("구글")) {
response.sendRedirect("https://www.google.com");
}
%>
</body>
</html>



============================================

[HTML]


<!DOCTYPE html>

<html>

<head>

<style>

body{

text-align: center;

}

fieldset{

padding-top: 50px;

padding-bottom: 50px;

width: 400px;

border: 3px dotted black;

margin: 0 auto;

}

input{

width: 200px;

height: 35px;

margin-top: 10px;

}

</style>

<meta charset="EUC-KR">

<title>Insert title here</title>

</head>

<body>

<fieldset>

<legend><h1>로그인</h1></legend>

<form action="ex13Join.jsp">

<input type="text" name="id" placeholder="id">

<input type="text" name="pw" placeholder="pw">

<input type="submit" value="로그인">

</form>

</fieldset>

</body>

</html>



[Join.jsp]


<%@ page language="java" contentType="text/html; charset=EUC-KR"

    pageEncoding="EUC-KR"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">

<title>Insert title here</title>

</head>

<body>

<%

String id = request.getParameter("id");

String pw = request.getParameter("pw");

if(id.equals("aaaa") && pw.equals("1111")) {

response.sendRedirect("ex13JoinTrue.jsp");

} else {

response.sendRedirect("ex13JoinFalse.jsp");

}

%>

</body>

</html>


[joinTrue.jsp]


<%@ page language="java" contentType="text/html; charset=EUC-KR"

    pageEncoding="EUC-KR"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">

<title>Insert title here</title>

<style>

body{

text-align: center;

}

fieldset{

padding-top: 50px;

padding-bottom: 50px;

width: 400px;

border: 3px dotted black;

margin: 0 auto;

}

input{

width: 200px;

height: 35px;

margin-top: 10px;

}

</style>

</head>

<body>

<fieldset>

<h1>aaaa님</h1> <br>

접속을 환영합니다.

</fieldset>

</body>

</html>


[joinFalse.jsp]


<%@ page language="java" contentType="text/html; charset=EUC-KR"

    pageEncoding="EUC-KR"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">

<title>Insert title here</title>

<style>

body{

text-align: center;

}

fieldset{

padding-top: 50px;

padding-bottom: 50px;

width: 400px;

border: 3px dotted black;

margin: 0 auto;

}

input{

width: 200px;

height: 35px;

margin-top: 10px;

}

</style>

</head>

<body>

<fieldset>

<h1>로그인 정보를 확인하세요.</h1><br>

<a href="ex13Join.html">Go back to Login</a>

</fieldset>

</body>

</html>


 



============================================


============================================


'노트필기' 카테고리의 다른 글

[PPT] PPT  (0) 2017.08.11
[Web] JSPClass0720-2  (0) 2017.07.20
[Web] JSP class0719-1  (0) 2017.07.19
[Web] Servlet class07-19  (0) 2017.07.19
[Web] CSS class0718-1  (0) 2017.07.18