zoukankan      html  css  js  c++  java
  • JSP问卷调查

    Jsp中通过JavaBean实现问卷调查
    TestJsp15.jsp
    <%@ 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>Jsp中通过JavaBean实现问卷调查</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">
    </head>

    <body>
    <form action="TestJsp15_reg.jsp" method="post">
    <div>
    <h1>调查问卷</h1>
    <hr/>
    <ul>
    <li>你经常用哪些编程语言开发程序:</li>
    <li>
    <input type="checkbox" name="languages" value="Java">Java
    <input type="checkbox" name="languages" value="C#">C#
    <input type="checkbox" name="languages" value="C">C
    <input type="checkbox" name="languages" value="C++">C++
    </li>
    </ul>
    <ul>
    <li>你目前所掌握的技术:</li>
    <li>
    <input type="checkbox" name="technics" value="HTML">HTML
    <input type="checkbox" name="technics" value="CSS">CSS
    <input type="checkbox" name="technics" value="Servlet">Servlet
    <input type="checkbox" name="technics" value="JavaBean">JavaBean
    </li>
    </ul>
    <ul>
    <li>在学习中哪部分感觉有困难:</li>
    <li>
    <input type="checkbox" name="parts" value="JSP">JSP
    <input type="checkbox" name="parts" value="Struts2">Struts2
    </li>
    </ul>
    <input type="submit" value="提交">
    </div>
    </form>
    </body>
    </html>


    TestJsp15_reg.jsp
    <%@ 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>Jsp中通过JavaBean实现问卷调查</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">

    </head>

    <body>
    <jsp:useBean id="paper" class="com.test.bean.Paper"></jsp:useBean>
    <jsp:useBean id="convert" class="com.test.bean.Convert"></jsp:useBean>
    <jsp:setProperty property="*" name="paper"/>
    <div>
    <h1>调查结果</h1>
    <hr/>
    <ul>
    <li>
    你经常使用的编程语言:<%=convert.arr2Str(paper.getLanguages()) %>
    </li>
    <li>
    你目前所掌握的技术:<%=convert.arr2Str(paper.getTechnics()) %>
    </li>
    <li>
    在学习中感觉有困难的部分:<%=convert.arr2Str(paper.getParts()) %>
    </li>
    </ul>
    </div>
    </body>
    </html>


    Paper.java
    package com.test.bean;

    public class Paper {

    private String[] languages;
    private String[] technics;
    private String[] parts;

    public Paper(){

    }

    public String[] getLanguages(){
    return languages;
    }

    public void setLanguages(String[] languages){
    this.languages = languages;
    }

    public String[] getTechnics(){
    return technics;
    }

    public void setTechnics(String[] technics){
    this.technics = technics;
    }

    public String[] getParts(){
    return parts;
    }

    public void setParts(String[] parts){
    this.parts = parts;
    }
    }

    Convert.java
    package com.test.bean;

    public class Convert {

    /**
    * 将数组转换成字符串
    * @param arr 数组
    * @return 字符串
    */
    public String arr2Str(String[] arr){
    //实例化StringBuffer
    StringBuffer sb = new StringBuffer();
    //判断arr是否为有效数组
    if(arr != null && arr.length > 0){
    //遍历数组
    for(String s : arr){
    //将字符串追加到StringBuffer中
    sb.append(s);
    //将","追加到StringBuffer中
    sb.append(",");
    }
    //判断字符串长度是否有效
    if(sb.length() > 0){
    //截取字符
    sb = sb.deleteCharAt(sb.length()-1);
    }
    }
    //返回字符串
    return sb.toString();
    }
    }

  • 相关阅读:
    EL表达式
    JavaBean知识
    设计模型MVC和JavaBean
    JSP知识
    会话技术
    Servlet知识
    selenium+maven+testng+IDEA+git+jenkins自动化测试环境搭建(三)
    selenium+maven+testng+IDEA+git自动化测试环境搭建(二)
    selenium+testng+testng-xslt-1.1.2之报告完善
    selenium入门环境之浏览器问题
  • 原文地址:https://www.cnblogs.com/HEJian-man/p/5482595.html
Copyright © 2011-2022 走看看