jsp使用request.getParamter提交数据 并显示

来源:互联网 发布:英雄联盟控软件 编辑:程序博客网 时间:2024/06/01 10:32

//注册界面

<%@ 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 '1.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>
   <form action="2.jsp" method="post">
   用户名:<input type="text" name="txtname" value="<%=request.getAttribute("name")%>"/>
   
  密码: <input type="password" name="txtpwd"/>
  <br/>
  爱好:<input type="checkbox" name="hoddy" value="p"/>跑
   <input type="checkbox" name="hoddy" value="t"/>跳
   <input type="checkbox" name="hoddy" value="w"/>玩
   <br/>
   <input type="submit" name="txtsub"/>
   
   </form>
  </body>
</html>

//提交界面

<%@ 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 '1.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>
   <%
   request.setCharacterEncoding("utf-8");
   String name=request.getParameter("txtname");
   String name1=request.getParameter("txtpwd");
   String[] name2=request.getParameterValues("hoddy");
   if(name.equals("sa")&&name1.equals("sa")){
   //作用域保存
   request.setAttribute("name2",name2);
   request.setAttribute("name",name);
   request.setAttribute("name1", name1);
   
   
   request.getParameterValues(name);
   request.getRequestDispatcher("/3.jsp").forward(request, response);
   
   }else{
   request.setAttribute("name", name);
   request.getRequestDispatcher("/1.jsp").forward(request, response);
   
   }


    %>
   
   </form>
  </body>
</html>


<%@ 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 '3.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>
  欢迎: <%=request.getAttribute("name") %>
  <br/>
    密码: <%=request.getAttribute("name1") %>
    
  </body>
</html>


1 0
原创粉丝点击