欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

使用jsp实现表单与服务器的简单交互

程序员文章站 2024-03-20 16:31:16
...

下面代码主要功能为提交表单,将内容提交到另一个文件test1.jsp中显示 

<!doctype html>
<html lang="en">
 <head>
  <meta charset="UTF-8">
  <title>Document</title>
 </head>
 <body>
  <form action="test1.jsp" method="post">
    时(0-11): <input type="text"   name="hour"    placeholder="请输入0-11的数字"><br>
    分(0-59): <input type="text"   name="minute"  placeholder="请输入0-59的数字"><br>
    秒(0-59): <input type="text"   name="second"  placeholder="请输入0-59的数字"><br>
    <input type="submit" value="提交">
	<input type="reset"  value="重置">
</form>
 </body>
</html>

 下面为test1.jsp文件,负责接收HTML表单提交的信息,并在本页面进行输出。

<%@ page contentType="text/html" pageEncoding="GBK" %>
<html>
<head>
<title>表单交互</title>
</head>

<body>
<%
	String hour = request.getParameter("hour");
	String minute = request.getParameter("minute");
	String second = request.getParameter("second");
%>
<h2><%=hour%></h2>
<h2><%=minute%></h2>
<h2><%=second%></h2>
</body>
</html>

 未解决的疑惑:如何将后台的数据返回到前端?