Multiplication table?
Multiplication table?
本文关键字:table Multiplication 更新时间:2023-09-26
我需要编写两个具有以下属性的网页:
- 表单(决定这应该是html还是jsp文件)
表单包含一个包含两个字段的HTML表单:一个文本输入(称为"大小")和一个按钮
单击按钮时,会出现另一个页面。。
- 表(决定这是HTML还是JSP)
表显示了直到上一页中的"大小"的多规格表
示例:
如果点击3,则输出为:
1 2 3
2 4 6
3 6 9
此外,在"表格"中添加一个按钮,这样按下此按钮将使表格消失。
这是我的表单代码
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<body>
<h1>multiplication table</h1>
<form action="form_action.jsp" method="get">
Size: <input type="size" name="size" size="35" /><br />
<input type="submit" value="Submit" />
</form>
<p>Click on the submit button, and the input will be sent to a page
on the server called "form_action.jsp".</p>
</body>
</html>
和我的页面生成多规格表
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<head>
<title>Calculation from a form</title>
</head>
<body>
<div>Calculation</div>
<table border="Calculation">
<%
String temp = request.getParameter("number");
int x = Integer.parseInt(temp);
String table = "<table border='1' id='mytable'>";
for (int row = 1; row < 11; row++) {
%>
<tr>
<%
for (int column = 1; column < 11; column++) {
%>
<td><tt><%=row * column%></tt></td>
<%
}
%>
</tr>
<%
}
%>
</table>
</body>
有人能帮我开始吗?
在您的第一个页面中,您已经输入了命名大小为<input type="size" name="size" size="35" />
的值,但在form_action.jsp
中,您正试图从number
中获取值
String temp = request.getParameter("number");
将其更改为size
String temp = request.getParameter("size");
您正在将该值解析为int x
,但从未在for
s中使用过它。如果更正该值,它就可以了。
这就是您想要的:form_action.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<body>
<h1>multiplication table</h1>
<table border="1">
<%
int size = Integer.valueOf(request.getParameter("size"));
for (int row = 1; row <= size; row++) {
%>
<tr>
<%
for (int column = 1; column <= size; column++) {
%>
<td><%=row*column %></td>
<%
}
%>
</tr>
<%
}
%>
</table>
</body>
</html>
相关文章:
- Jquery - table.row(tr) is undefined
- javascript, ajax, table, colour
- jQuery parent() in table
- click-cell.bs.table是如何工作的
- onclick for table TD
- AppendChild Form / Table [Javascript/Html/PHP]
- Javascript: Output table
- onRowClick for react-bootstrap-table
- Google Fusion Table Javascript UPDATE Query?
- jquery .删除整个 li 或 table 元素后
- JQuery Click on Table
- AngularJS translate table
- CSS styling of <UL> as table
- Bootstrap Table
- 如何从SQL API代码迁移到Google Fusion Table API v1
- 选择/取消选择复选框,该复选框未按预期使用.coneast('table').find('tbo
- 使用Ember.js将新行动态插入到Table上下文中
- Jquery iterating table
- Multiplication table?
- Javascript Multiplication table