본문 바로가기

JSP(Java Server Page)

JSP 기본 예제(표만들기)

test2.jsp


<%@ page language="java" contentType="text/html; charset=UTF-8"

    pageEncoding="UTF-8"%>

<!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=UTF-8">

<title>Insert title here</title>

</head>

<body>


<form action="test2_ok.jsp" method="post">

가로 : <input type="text" name="row"><br/>

세로 : <input type="text" name="col"><br/>

<input type="submit" value="보내기">

</form>


</body>

</html>


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


test2_ok.jsp


<%@ page language="java" contentType="text/html; charset=UTF-8"

    pageEncoding="UTF-8"%>

 <%

  request.setCharacterEncoding("utf-8");

 int row=Integer.parseInt(request.getParameter("row"));

 int col=Integer.parseInt(request.getParameter("col"));

 

 int n=0;

 %>   

 

<!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=UTF-8">

<title>Insert title here</title>

</head>

<body>


<%

out.print("<table width='"+col*50+"'border='1'>");

for(int i=1; i<=row; i++){

out.print("<tr height='25'>");

for(int j=1; j<=col; j++){

out.print("<td>"+(++n)+"</td>");

}

out.print("</tr>");

}

out.print("</table>");

%>


</body>

</html>