JSP Survey Library           SourceForge.net Logo

How To Build A Survey: Using JSP

About JSP/Java
JSP Commands and Tags
    JSP Command: include file
    JSP Tag: surveypage
    Other JSP Tags
More About JSP/Java

About JSP/Java

A huge benefit of the survey tool is that if you know how to write Java and JSP, you can make your survey do almost anything. Branching, advanced branching, randomizing pages, and nearly anything you can think of the logic for is all possible when you edit the you web pages directly. If you want to understand this, it is a good idea that you have some experience in programming, especially programming in Java.

First, you'll need to find where on your server your web page files are stored. When you user the survey manager, click "Edit Survey". Near the bottom of the page, it will tell you where on the server the files are stored for this webapp. Usually they'll be inside the folder where you installed Apache Tomcat, in one of these places:
  • If you're running Windows, it's probably in C:\Program Files\Apache Tomcat\ or a similar folder, inside the webapps folder.
  • If you are using Linux or Unix, you can type "locate "*tomcat*/webapps"" and it will show you a list of all the possible places
What is a JSP page?

File: page1.jsp (included in the default survey, when you've made a new survey)

<%@include file="include_questionnaire.jsp"%>

<survey:surveypage
    pageName="Page 1"

    nextPage="page2.jsp"

    submitButtonText="Next"
    pageWidth="600"

    rememberPageUserIsOn="true"
    pageToLoginTo="index.jsp"
    tableToVerifyLoginTo="Users"
    userIDField="ID"
    isLoginPage="false"

    databaseName="<%=databaseName%>"
    />


<%@include file="survey_end.jsp"%>


A "JSP" page is similar to an HTML file, except that the file name ends with ".jsp" instead of ".html". And, it's dynamic -- HTML pages don't change when the user visits them, but a JSP page does.

JSP Commands and Tags

In page1.jsp, there are several commands that create the survey and show the page. Let's go through them one at a time.

JSP Command: include file


<%@include file="include_questionnaire.jsp"%>

This includes another JSP page, the contents of which you can imagine to be "included" directly into this page, as if copied and pasted automatically. The file named "include_questionnaire.jsp" you can see that it includes several other files, and it starts the beginning of a webpage. Similarly, at the end of page1.jsp, you'll see


<%@include file="survey_end.jsp"%>

This does the same thing as the first one, including a bunch of HTML and other things that end up at the bottom of the page.

JSP Tag: surveypage

The middle tag will load the survey and the questions that you made in the Survey Editor:


<survey:surveypage
    pageName="Page 1"

    nextPage="page2.jsp"

    submitButtonText="Next"
    pageWidth="600"

    rememberPageUserIsOn="true"
    pageToLoginTo="index.jsp"
    tableToVerifyLoginTo="Users"
    userIDField="ID"
    isLoginPage="false"

    databaseName="<%=databaseName%>"
    />

This is called a "JSP tag" -- it loads a little program which creates HTML and puts it into the page. The tag's name is "survey:surveypage", shown at the beginning. This loads one page of the survey. The text in the middle are parameters. To see how to use and modify JSP Tags, see the surveypage documentation.

Other JSP Tags

For many JSP tags, there is better information in the JavaDocs.

More Information About JSP/Java

For more information about using JSP and Java, you may want to try a tutorial or two:

JHU JSP Tutorial
JSPTut.com JSP Tutorial
The Java Tutorial (trails about "swing" and "gui" are not relevant to JSP. However, basic Java knowledge will help a great deal if you want to make advanced features)

 

 

Back To "Building a Survey"

  Home
Screenshots and Demos
Help
  Installing
Building A Survey Using JSP
surveypage tag
Repeated Measures
Changing Data
Getting Data
Clustering Survey
Java Web Start
Developers
Download
Contributors