Jsp表单测试-checkbox获取,radio获取


源程序:

 

form.jsp中的代码:

 

<%@ page language="java"import="java.util.*"pageEncoding="UTF-8"%>

<%

String path = request.getContextPath();

String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

%>

 

DOCTYPEHTMLPUBLIC "-//W3C//DTDHTML 4.01 Transitional//EN">

<html>

  <head>

    <basehref="<%=basePath%>">

   

    <title>My JSP'form.jsp' starting pagetitle>

   

    <metahttp-equiv="pragma"content="no-cache">

    <metahttp-equiv="cache-control"content="no-cache">

    <metahttp-equiv="expires"content="0">   

    <metahttp-equiv="keywords"content="keyword1,keyword2,keyword3">

    <metahttp-equiv="description"content="This is my page">

   

 

  head>

 

  <body>

    <formaction="./form_resp.jsp"method="post">

       username:<inputtype="text"name="username"><br>

       password: <input type="password"name="password"><br>

       兴趣:学习<inputtype="checkbox"name="interest"value="学习">

                  旅游<inputtype="checkbox"name="interest"value="旅游">

                  睡觉<inputtype="checkbox"name="interest"value="睡觉"><br>

       性别:男<inputtype="radio"name="gender"value="">

             <inputtype="radio"name="gender"value=""><br>

       学历:<selectname="xueli">

              <optionvalue="">option>

              <optionvalue="小学">小学option>     

               <option value="初中">初中option>

               <option value="高中">高中option>

              <optionvalue="大学">大学option>

           select>

           <br>

 

                   说明:<textareaname="text">textarea><br>

 

       图片:<imgsrc="images/google.jpg"height=80pxwidth=200px><br>

       文件上传:<inputtype="file"><br>

 

       <inputtype="submit"value="submit">   <inputtype="reset"value="reset">   <inputtype="button"value="button"onclick="javascript:alert('hello world');">

 

    form>

 

  body>

html>

 

form_resp.jsp中的代码:

 

<%@pageimport="java.awt.Checkbox"%>

<%@ page language="java"import="java.util.*"pageEncoding="UTF-8"%>

<%

String path = request.getContextPath();

String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

%>

 

DOCTYPEHTMLPUBLIC "-//W3C//DTDHTML 4.01 Transitional//EN">

<html>

  <head>

    <basehref="<%=basePath%>">

   

    <title>My JSP'form_resp.jsp' starting pagetitle>

   

    <metahttp-equiv="pragma"content="no-cache">

    <metahttp-equiv="cache-control"content="no-cache">

    <metahttp-equiv="expires"content="0">   

    <metahttp-equiv="keywords"content="keyword1,keyword2,keyword3">

    <metahttp-equiv="description"content="This is my page">

   

 

  head>

 

  <body>

    <% String username = request.getParameter("username");

        String password = request.getParameter("password");

        String[] values =request.getParameterValues("interest");

        String gender = request.getParameter("gender");

        String xueli = request.getParameter("xueli");

        String text = request.getParameter("text");

       

        out.println("username:"+username+"
"
);

        out.println("password:"+password+"
"
);

        out.println("兴趣: ");

        for(String value :values){

              Stringval = new String(value.getBytes("iso-8859-1"),"utf-8");

               out.println(val);

        }

       

        String gen = newString(gender.getBytes("iso-8859-1"),"utf-8");

        out.println("
"
+"性别: "+gen+"
"
);

       

        String xue = newString(xueli.getBytes("iso-8859-1"),"utf-8");

        out.println("学历: "+xue+"
"
);

        out.println("说明: "+text+"
"
);

       

    %>

   

   

  body>

html>

 

运行结果:

 

form.jsp页面:

Jsp表单测试-checkbox获取,radio获取_第1张图片

 

form_resp.jsp表单响应页面:

 Jsp表单测试-checkbox获取,radio获取_第2张图片

你可能感兴趣的:(jsp技术)