创建一个表单数据,servlet后台我要输出
实现一个表单数据提交,sevlet将它显示出来。
【效果截图】:
#输入
#提交
================================================================================
【index.jsp代码】
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>填写留言信息</title> </head> <body> <form id="form1" name="form1" method="post" action="FirstServlet"> 留 言 人: <input name="person" type="text" id="person" /> <br /> <br /> 留言内容: <textarea name="content" cols="30" rows="5" id="content"></textarea> <br /> <br /> <input type="submit" name="Submit" value="提交" /> <input type="reset" name="Submit2" value="重置" /> </form> </body> </html>
整个页面由简单的html语言构成,生成一个表单,form id="form1" name="form1" method="post" action="FirstServlet “提交事件处理对象FirstServlet
public class FirstServlet extends HttpServlet { private static final long serialVersionUID = 1L; /** * @see HttpServlet#HttpServlet() */ public FirstServlet() { super(); // TODO Auto-generated constructor stub } /** * 澶勭悊HTTP POST璇锋眰 */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("UTF-8");// String person=request.getParameter("person"); // String content=request.getParameter("content"); // response.setContentType("text/html;charset=UTF-8"); // PrintWriter out=response.getWriter(); // out.println("<html><head><title>获取留言信息</title></head><body>"); out.println("留言人"+person+"<br>"); out.println("留言内容:"+content+"<br>"); out.println("<a href='index.jsp'>返回</a>"); out.println("</body></html>"); out.close(); } }
处理表单数据这里较为简单,相信大家也看得懂,这里也看到了servlet处理网页数据的能力,以及它自己也能对网页内容进行一定的输出
相关推荐
JudeJoo 2020-08-21
meleto 2020-08-15
lantingyue 2020-07-30
zyjj 2020-07-27
pengpengflyjhp 2020-07-19
htofly 2020-07-09
三动 2020-06-21
hyxinyu 2020-06-08
洗尽铅华 2020-06-07
shayuchaor 2020-06-07
xiamubawei 2020-06-04
方志朋 2020-05-30
一片荷叶 2020-05-27
spring艳 2020-05-16
zhangdy0 2020-05-06
80304053 2020-05-04
neweastsun 2020-05-04
shuiluobu 2020-05-01
itjavashuai 2020-04-26