Eggs Sunny Side Up
본문 바로가기
Web/JSP_Servlet

객체실습_html에서 값 입력 후 jsp에서 출력

by guswn100059 2023. 4. 19.

html)

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>

	<h1>성적확인 프로그램</h1>
	
	<form action="Ex09request.jsp">
		이름 <input type="text" name="name">
		<br>
		Java점수 <input type="number" name="java">
		<br>
		web점수 <input type="number" name="web">
		<br>
		IOT점수 <input type="number" name="iot">
		<br>
		Android점수 <input type="number" name="android">
		<br>
		
		<input type="submit" value="전송">
		
	</form>
	
	
</body>
</html>

 

jsp)

`<%@page import="java.io.PrintWriter"%>
<%@ 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>
	<%	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 total = (double)(java+web+iot+android)/4;
		
		String grade = "";
		
		
		if(total>=95) grade = "A+";
		else if (total>=90) grade = "A";
		else if(total>=85) grade = "B+";
		else if(total>=80) grade = "B";
		else grade = "F";
		
	%>
		
		이름 <%=name %> <br>
		Java점수 <%=java %> <br>
		Web점수 <%=web %> <br>
		IOT점수 <%=iot %> <br>
		Android 점수 <%=android %> <br>
		평균 <%=total %> <br>
		학점 <strong><%=grade %></strong> <br>
	
</body>
</html>

 


html)

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
	<h3>랜덤숫자입력</h3>
	
	<form action="ex11write.jsp">
		<input type="number" name="num"> <br>
		
		<input type="submit" value="생성하기">
		
	</form>
</body>
</html>

 

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>
	
	<h3>랜덤당첨 작성</h3>
	
	<form action="ex11result.jsp">
		주제 : <input type="text" name="topic"><br>
		<% int num = Integer.parseInt(request.getParameter("num"));%>
		<% for(int i = 0; i < num; i++) {%>
			아이템<%=i+1 %>: <input type="text" name="item"><br>
		<% } %>
		
		<input type="submit" value="시작">
	</form>
	
</body>
</html>

 

jsp)

<%@page import="java.util.Random"%>
<%@ 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>
	<h3>랜덤당첨결과</h3>
	<%
		String result = request.getParameter("topic");
		String[] item = request.getParameterValues("item");
		
		Random rd = new Random();
		int num = rd.nextInt(item.length);
		
				
	%>
	
	<%=result %><br>
	<%=item[num] %>
	
</body>
</html>

'Web > JSP_Servlet' 카테고리의 다른 글

MVC_회원가입 시스템  (0) 2023.04.24
Session  (1) 2023.04.19
쿠키  (0) 2023.04.18
forward & redirect  (0) 2023.04.18
JSP 객체_html코드 안에서 Java코드 사용  (0) 2023.04.18

댓글