Servlet读取表单参数

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

index.jsp页面代码%@pagelanguage=javacontentType=text/html;charset=utf-8pageEncoding=utf-8%!DOCTYPEhtmlPUBLIC-//W3C//DTDHTML4.01Transitional//EN=Content-Typecontent=text/html;charset=utf-8titleServlet生成动态信息示例/title/headbodyformid=form1name=form1method=postaction=Dynamiclabel请输入您的名字:/labelinputtype=textname=userName/pinputtype=submitname=Submitvalue=提交//p/form/body/htmlDynamic.java代码packagecom.cc;importjava.io.IOException;importjava.io.PrintWriter;importjavax.servlet.ServletException;importjavax.servlet.annotation.WebServlet;importjavax.servlet.http.HttpServlet;importjavax.servlet.http.HttpServletRequest;importjavax.servlet.http.HttpServletResponse;/***ServletimplementationclassDynamic*/@WebServlet(/Dynamic)publicclassDynamicextendsHttpServlet{privatestaticfinallongserialVersionUID=1L;/***@seeHttpServlet#HttpServlet()*/publicDynamic(){super();//TODOAuto-generatedconstructorstub}/***@seeHttpServlet#doGet(HttpServletRequestrequest,HttpServletResponseresponse)*/protectedvoiddoGet(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletException,IOException{//TODOAuto-generatedmethodstub//response.setContentType(text/html;charset=gbk);request.setCharacterEncoding(utf-8);response.setCharacterEncoding(utf-8);PrintWriterout=response.getWriter();out.println(htmlheadmetahttp-equiv='Content-Type'content='text/html;charset=utf-8'titleServlet生成动态网页/title/headbodyp);out.print(非法的请求);out.println(/p/body/html);}/***@seeHttpServlet#doPost(HttpServletRequestrequest,HttpServletResponseresponse)*/protectedvoiddoPost(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletException,IOException{//TODOAuto-generatedmethodstubrequest.setCharacterEncoding(utf-8);StringuserName=request.getParameter(userName);Stringip=request.getRemoteAddr();//response.setContentType(text/html;charset=gbk);request.setCharacterEncoding(utf-8);response.setCharacterEncoding(utf-8);PrintWriterout=response.getWriter();out.println(htmlheadmetahttp-equiv='Content-Type'content='text/html;charset=utf-8');out.println(titleServlet生成动态网页/title);out.println(/headbodyp);out.print(欢迎strong);out.print(userName);out.print(/strong来自strong);out.print(ip);out.print(/strong);out.println(的朋友/p/body/html);}}

1 / 3
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功