我的成长磨练,每天写博客,年轻人,卷起袖子,来把手弄脏吧! ------ 博客首页

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();
}
}

posted on 2016-05-11 17:05  清风mam  阅读(1262)  评论(0编辑  收藏  举报

web应用开发&研究 - 创建于 2014年8月17日

这是一位web前端开发工程师的个人站,内容主要是网站开发方面的技术文章,大部分来自学习或工作,部分来源于网络,希望对大家有所帮助。

致力于web应用开发&研究工作,专注web前端开发,关注互联网前沿技术与趋势。


Font Awesome | Respond.js | Bootstrap中文网