zoukankan      html  css  js  c++  java
  • jsp表单提//jsp表单接收

    form 表单提交

    action=“  ” 引号内,表示提交到哪 ===>  action="do_post.jsp"  把资料提交到另一个文件

    <%@ 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="do_post.jsp"method="post" >
        用户名:<input type="text" id="" name="user"><br>                           //name=" ",接收时会根据name的值
        密码: &nbsp;<input type="password" id="" name="pass"><br>       
        性别:<br><input type="radio" id="" value="nan" name="sex">              //value=“ ”,value值如果不写,接收只会返回on(表示点击了)
    <input type="radio" id="" value="nv" name="sex"><br>             兴趣:<br> <input type="checkbox" id="" name="xing" value="qixing">骑行 <input type="checkbox" id="" name="xing" value="paoshan">爬山 <input type="checkbox" id="" name="xing" value="youyong">游泳 <input type="checkbox" id="" name="xing" value="bengji">蹦极 <br><br> 个人说明:<br> <textarea rows="4" cols="30" name="duo"></textarea><br> <button type="submit">提交</button> </form> </body> </html>

    得到如下界面:

    点击提交之后,会提交到action=“”内的地址

    <%@ 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>
    
    <%
    
    String srt=request.getParameter("user");                    // 通过表单中name的值,得到数据
    request.setAttribute("us", srt);                //
    
    String pass=request.getParameter("pass");
    request.setAttribute("pass", pass);
    
    String sex=request.getParameter("sex");
    request.setAttribute("sex", sex);
    
    String xing[]=request.getParameterValues("xing");     // 多选框是接收多个数据,用getParameterValues,会返回一个数组,用数组接收  
    request.setAttribute("xing", xing);
    
    String duo=request.getParameter("duo");
    request.setAttribute("duo", duo);
    %>
    
    <p>${us }</p>
    <p>${pass }</p>
    <p>${sex }</p>
    <%
    for(String x: xing){                          //在输出复选框内容,用循环遍历
    %>
    <br>
    <%= x%>
    <% 
    }
    
    %>
    
    <p>${duo }</p>
    
    </body>
    </html>

    得出下面的结果

  • 相关阅读:
    docker相关
    多线程
    设计模式
    ftp下载乱码问题
    Windows无法启动SQL server 代理服务(服务器)错误1067:进程意外终止
    Struts2 if标签
    Java项目编译时经常会出现不编译,或者报一些假性错误
    ajaxSubmit 上传文件 提示下载json处理
    MySQL中优化sql语句查询常用的30种方法
    mybatis 中的where标签
  • 原文地址:https://www.cnblogs.com/xiandong/p/8044890.html
Copyright © 2011-2022 走看看