JSP Questionnaire Survey

Source: Internet
Author: User

Using JavaBean to implement questionnaire survey in JSP
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" >
<base href= "<%=basePath%>" >

<title>jsp through JavaBean to achieve the questionnaire survey </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" >

<body>
<form action= "testjsp15_reg.jsp" method= "POST" >
<div>
<ul>
<li> which programming languages do you often use to develop programs:</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> The technical:</li> you are currently mastering
<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> in learning which part of the feeling has difficulty:</li>
<li>
<input type= "checkbox" name= "Parts" value= "JSP" >jsp
<input type= "checkbox" name= "Parts" value= "Struts2" >struts2
</li>
</ul>
<input type= "Submit" value= "Submission" >
</div>
</form>
</body>


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"
<base href= " <%=basePath%>

<title>jsp The survey </title> by JavaBean;

<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";


<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>
<ul>
<li>
Programming languages you often use: <%=convert.arr2str (Paper.getlanguages ())%>
</li>
<li>
Your current skills: <%=convert.arr2str (Paper.gettechnics ())%>
</li>
<li>
Parts that feel difficult to learn: <%=convert.arr2str (Paper.getparts ())%>
</li>
</ul>
</div>
</body>


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 {

/**
* Convert an array into a string
* @param arr Array
* @return String
*/
Public String arr2str (string[] arr) {
Instantiate StringBuffer
StringBuffer sb = new StringBuffer ();
Determine if arr is a valid array
if (arr! = null && arr.length > 0) {
Iterating through an array
for (String S:arr) {
Append a string to the StringBuffer
Sb.append (s);
Append "," to StringBuffer
Sb.append (",");
}
Determines whether the string length is valid
if (sb.length () > 0) {
Intercept characters
SB = Sb.deletecharat (Sb.length ()-1);
}
}
return string
return sb.tostring ();
}
}

JSP Questionnaire Survey

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.