实验Servelt.docx_第1页
实验Servelt.docx_第2页
实验Servelt.docx_第3页
实验Servelt.docx_第4页
实验Servelt.docx_第5页
已阅读5页,还剩1页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

Servlet编程要求:编写Servlet处理表单的程序。要求:熟悉Servlet的基本概念,掌握Servlet的工作原理和生命周期,熟悉Servlet处理表单数据的编程方式,了解Servlet会话管理的编程设计基础。实验内容:1. 编写一个Servlet处理表单的程序,客户端以HTML表单方式向服务器提交数据,提交方法采用Post方法,使用相应方法获取表单数据。2. 程序实现功能如图所示:注意:项目名为ServletProject,表单文件名为test.html,获取表单的Servlet名为testServlet。Index.jsp 潜在用户网络调查 姓名: EMAIL: 年纪: 小于18 18-25 25-40 大于40 编程时间: 小于6个月 6-12个月 大于6个月 使用操作系统: WinXP Win2000/2003 FresBSD MacOS LINUX other 使用编程语言 C C+ C# PYTHON JAVA VB DEPTI 建议: 请在此输入你的建议 Testservlet.javapackage information;import java.io.IOException;import java.io.PrintWriter;import javax.servlet.ServletException;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import javax.servlet.http.HttpSession;public class testservlet extends HttpServlet /* * Constructor of the object. */public testservlet() super();/* * Destruction of the servlet. */public void destroy() super.destroy(); / Just puts destroy string in log/ Put your code here/* * The doGet method of the servlet. * * This method is called when a form has its tag value method equals to get. * * param request the request send by the client to the server * param response the response send by the server to the client * throws ServletException if an error occurred * throws IOException if an error occurred */public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException public void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException response.setContentType(text/html;charset=GB2312); PrintWriter out = response.getWriter(); byte b1=request.getParameter(myname).getBytes (ISO-8859-1);String s1=new String(b1,UTF-8);byte b2=request.getParameter(email).getBytes(ISO-8859-1); String s2=new String(b2,UTF-8); byte b3=request.getParameter(age).getBytes(ISO-8859-1); String s3=new String(b3,UTF-8);byte b4=request.getParameter(time).getBytes(ISO-8859-1); String s4=new String(b4,UTF-8); String b5=request.getParameterValues(system); HttpSession session1=request.getSession(true); session1.setAttribute(st,);for(int i=0;ib5.length;i+) session1.setAttribute(st,session1.getAttribute(st)+b5i+ ); String s=(String)session1.getAttribute(st);byte f2=s.getBytes(ISO-8859-1);String s5=new String(f2,UTF-8);String b6 = request.getParameterValues(language); HttpSession session=request.getSession(true); session.setAttribute(str,);for(int i=0;ib6.length;i+) session.setAttribute(str,session.getAttribute(str)+b6i+ ); String ss =(String)session.getAttribute(str);byte f1=ss.getBytes(ISO-8859-1);String s6=new String(f1,UTF-8);byte b7=request.getParameter(suggest).getBytes(ISO-8859-1); String s7=new String(b7,UTF-8);out.println();out.println(用户的信息);out.println(姓名: +s1+); out.println(EMAIL:+s2+); out.println(年纪: +s3+);out.println(编程时间: +s4+);out.println(使用操作系统: +s5+);out.println(使用编程语言: +s6);out.println();out.println(建议: +s7+);out.print

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论