Formato de salida JSP 9x9

La forma de salida 9x9 de Jsp es realmente muy simple, al igual que la forma de salida 9x9 de Java.

El primero:

<%@ 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>
	<%
		out.print("<table border = 1\">");
		for (int i = 0; i < 9; i++) {
    
    
			out.print("<tr>");
			for (int j = 0; j < 9; j++) {
    
    
				out.print("<td>" + i * j + "</td>");
			}
			out.print("</tr>");
		}
		out.print("</table>");
	%>
</body>
</html>

Efecto de la operación: el
Inserte la descripción de la imagen aquí
segundo método:

<%@ 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>
	<table border="1">
		<%
			for (int i = 0; i < 9; i++) {
    
    
		%>
			<tr>
		<%
			for (int j = 0; j < 9; j++) {
    
    
		%>
			<td><%=i * j%></td>
		<%
			}
		%>
			</tr>
		<%
			}
		%>
	</table>
</body>
</html>

Captura de pantalla del efecto de ejecución:
Inserte la descripción de la imagen aquí
estos dos métodos tienen el mismo efecto, pero generalmente el segundo método se usa para escribir código Java y código HTML por separado.

Para mejorar la dificultad, el usuario ingresa varias filas y varias columnas, y luego genera varias filas y varias columnas. Aquí se necesita un método.

request.getParameter();

Puede obtener el
código HTML de valor del formulario en HTML:

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
	<form action="NewFile.jsp" method="post">
		行:<input type="text" name="line">
		列:<input type="text" name="row">
		<input type="submit" value="提交">
	</form>
</body>
</html>

código 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>
	<table border="1">
		<%
			//获取表单输入的值
			String s_line = request.getParameter("line");
			String s_row = request.getParameter("row");
			//将String型转换成int型
			int line = Integer.parseInt(s_line);
			int row = Integer.parseInt(s_line);
			for(int i = 0; i<line; i++){
    
    
		%>
			<tr>
		<%
			for(int j = 0; j<row; j++){
    
    
		%>
			<td><%=i*j %></td>
		<%
			}
		%>
			</tr>
		<%
			}
		%>
	</table>
	
</body>
</html>

Ejecutar captura de pantalla:
Inserte la descripción de la imagen aquí
Inserte la descripción de la imagen aquí

Supongo que te gusta

Origin blog.csdn.net/javanofa/article/details/104822286
Recomendado
Clasificación