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;
}
}
[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 |