数据交互一

来源:互联网 发布:淘宝上的头层牛皮沙发 编辑:程序博客网 时间:2024/05/18 03:41
<strong><span style="font-size:18px;">注册页面</span></strong>
<strong><span style="font-size:18px;"><%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%><%String path = request.getContextPath();String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html>  <head>    <base href="<%=basePath%>">    <title>My JSP 'index.jsp' starting page</title><span style="white-space:pre"></span><meta http-equiv="pragma" content="no-cache"><span style="white-space:pre"></span><meta http-equiv="cache-control" content="no-cache"><span style="white-space:pre"></span><meta http-equiv="expires" content="0">    <span style="white-space:pre"></span><meta http-equiv="keywords" content="keyword1,keyword2,keyword3"><span style="white-space:pre"></span><meta http-equiv="description" content="This is my page"><span style="white-space:pre"></span><!--<span style="white-space:pre"></span><link rel="stylesheet" type="text/css" href="styles.css"><span style="white-space:pre"></span>-->  </head>    <body>    <form method="post"  action="info.jsp">    <span style="white-space:pre"></span>用户名:<input  type="text" name = "name"/>    <span style="white-space:pre"></span>密码:<input  type="password" name = "pwd"/>    <span style="white-space:pre"></span><input  type="checkbox" name ="love" value="chi"/>吃    <span style="white-space:pre"></span><input  type="checkbox" name ="love" value="he"/>喝    <span style="white-space:pre"></span><input  type="checkbox" name ="love" value="piao"/>嫖    <span style="white-space:pre"></span><input  type="checkbox" name ="love" value="du"/>赌    <span style="white-space:pre"></span><input  type="submit"  value="提交"/>    </form>    <span style="white-space:pre"></span>    <br>  </body></html></span></strong>
<strong><span style="font-size:18px;"></span></strong>
<strong><span style="font-size:18px;">响应操作的页面</span></strong>
<strong><span style="font-size:18px;"></span></strong>
<strong><span style="font-size:18px;"><%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%><%String path = request.getContextPath();String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html>  <head>    <base href="<%=basePath%>">        <title>My JSP 'info.jsp' starting page</title>    <meta http-equiv="pragma" content="no-cache"><meta http-equiv="cache-control" content="no-cache"><meta http-equiv="expires" content="0">    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"><meta http-equiv="description" content="This is my page"><!--<link rel="stylesheet" type="text/css" href="styles.css">-->  </head>    <body>  <!-- 编码格式处理  方式一:method="post" >>>  方式二:method="get" >>>  方式三:需改jsp容器的编码集,如Tomcat  URIEncoding=“UTF-8"添加到Tomcat配置文件server.xml   -->    <%    //request是将客户端信息发送到服务端    //response是客户端交互响应:去服务端检索信息,返回相应的结果    request.setCharacterEncoding("UTF-8");//post提交方式:编码转换    String name = request.getParameter("name");//根据页面表单组件名称(name)获取提交数据    /*name= new String(name.getBytes("ISO-8859-1"),"UTF-8");    get提交方式编码处理     原理:通过name.getBytes("ISO-8859-1")按照ISO-8859-1字符集编码吧name字符转换成byte数组     再通过new String();方法使用指定的UTF-8字符编码集吧byte构造成String     */    String pwd = request.getParameter("pwd");    String[] love = request.getParameterValues("love");//根据一组同名的html元素name获取数据    if(name.equals("aaa")&&pwd.equals("aaa")){//此处需要去数据库查询验证    //转发(服务端操作  服务器进行转换页面,转换后的页面也可以的到客户端的输入信息)    request.getRequestDispatcher("Huanying.jsp").forward(request, response);    }else{    //重定向(客户端操作 再次请求服务器)    response.sendRedirect("Cuowu.jsp");    }     %>     <!-- 以下代码 仅用于测试是否提交成功(实际项目中不需要) -->     <p>     <%=name %>     <%=pwd %><%if(love!=null){for(int i =0;i<love.length;i++){out.print("爱好:"+love[i]);}} %> </p>  </body></html></span></strong>


0 0
原创粉丝点击