jsp 笔记 关于数据交互

来源:互联网 发布:南京邮电大学网络攻防 编辑:程序博客网 时间:2024/06/05 18:56
<%@ page language="java" contentType="text/html; charset=UTF-8"    pageEncoding="UTF-8"%><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>Insert title here</title></head><body><form action="index.jsp" method="post">      用户名: <input type="text" name="txtname" value="<%=request.getAttribute("name") %>"/>    密码:   <input type="password" name="txtpwd"/>       <input type="submit" value="提交"/>        <br/>       爱好<input type="checkbox" name="hello" value="跑步"/>      <input type="checkbox" name="hello" value="游泳"/>       <input type="checkbox" name="hello" value="骑马"/></form></body></html>

<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>Insert title here</title></head><body><%request.setCharacterEncoding("utf-8");String [] jihe=request.getParameterValues("hello");    String a="";    String b="";    String c="";if(jihe!=null){switch(jihe.length){case 1:a=jihe[0];break;case 2:a=jihe[0];b=jihe[1];break;case 3:a=jihe[0];b=jihe[1];c=jihe[2];break;}}   String name = request.getParameter("txtname");System.out.println(name);String pwd = request.getParameter("txtpwd");if (name.equals("中文") && pwd.equals("1")) {//保存作用域的值request.setAttribute("name", name);//request.setAttribute("jihe", jihe);   request.setAttribute("jihe0", a);request.setAttribute("jihe1",b);request.setAttribute("jihe2", c); //跳转request.getRequestDispatcher("/go.jsp").forward(request,response);}else{//保存值request.setAttribute("name", name);//request.getRequestDispatcher("/regit.jsp").forward(request,response);//重定义response.sendRedirect("/Day_02shili/regit.jsp");}if(jihe!=null){for(String item:jihe){out.print(item+" ");}}%>输入错误页面</body></html>

<%@ page language="java" contentType="text/html; charset=UTF-8"    pageEncoding="UTF-8"%><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>Insert title here</title></head><body>欢迎你 <%=request.getAttribute("name") %> <%=request.getAttribute("jihe0") %><%=request.getAttribute("jihe1") %> <%=request.getAttribute("jihe2") %>     </body></html>

0 0
原创粉丝点击