- Please note this tutorial is not the only means of randomization by far. There may very well be a much faster and better way for your application. Specificaly, using Repeated Measures. For additional info check the FAQ
- Before following these examples, make sure your survey is setup for jsp and you are familiar with how to use the Web Survey Toolbox GUI
- Warning at the time posting, I have not yet tested all the code. Will do so shortly.
Now that all the issues are on the table, on with the show....
Basic JSP Randomization example:
In this example we will randomize the order of 3 pages (page1.jsp, page2.jsp, and page3.jsp). There are 4 options for what type of random you can use. For this example we will use redirectRandomOrderTo, of just plain random.
- Create 3 pages in the Survey Manager and make 3 long answer questions on each page. Name the pages Page 1, Page 2, and Page 3.
- Make the JSP pages for each of the three pages you created in the Survey Manager.
- Download page1.jsp and change the nextPage variable to random.jsp (see Code Example 1 below). For help with uploading or downloading see here.
- Save page1.jsp as page2.jsp and repeat for page3.jsp.
- Change the pageName parameter in page2.jsp to "Page 2"
- Then change the nextPage variable to "random.jsp" (see code example 2 below)
- Change the pageName parameter in page3.jsp to "Page 3"
- Then change the nextPage variable to "random.jsp" (see code example 3 below)
- Then upload all thee pages.
page1.jsp
<%@include file="include_questionnaire.jsp"%> <survey:surveypage pageName="Page 1" pageWidth="600" nextPage="random.jsp" submitButtonText="Next" showSubmitButton="true" timeResponses="false" rememberPageUserIsOn="true" pageToLoginTo="index.jsp" tableToVerifyLoginTo="Users" isLoginPage="false" /> <%@include file="survey_end.jsp"%>
page2.jsp
<%@include file="include_questionnaire.jsp"%> <survey:surveypage pageName="Page 2" pageWidth="600" nextPage="random.jsp" submitButtonText="Next" showSubmitButton="true" timeResponses="false" rememberPageUserIsOn="true" pageToLoginTo="index.jsp" tableToVerifyLoginTo="Users" isLoginPage="false" /> <%@include file="survey_end.jsp"%>
page3.jsp
<%@include file="include_questionnaire.jsp"%> <survey:surveypage pageName="Page 3" pageWidth="600" nextPage="random.jsp" submitButtonText="Next" showSubmitButton="true" timeResponses="false" rememberPageUserIsOn="true" pageToLoginTo="index.jsp" tableToVerifyLoginTo="Users" isLoginPage="false" /> <%@include file="survey_end.jsp"%>
3. Create a new document in you favorite text editor (e.g. Word Pad, SimpleText, etc.) with the following (you can simply copy and paste this) :
random.jsp
<%@include file="include_questionnaire.jsp"%> <% if (redirectRandomOrderTo("Users", "RandomPageOrder", new String[]{"page1.jsp", "page2.jsp", "page3.jsp", " })) { } else { redirectTo("doneWithSurvey.jsp"); } %> <%@include file="survey_end.jsp"%>
General Code Explanation:
In general, this is an if statement that says, in the randomPageOrder column of the Users table, keep track of the order of pages the participant has visited. When the participant has randomly visited all of these listed pages, send them to the doneWithSurvey.jsp page.
Each part explained:
@Include file="include_questionaire.jsp"
= In this case tells the survey manager that this is the beginning of a questionnaire jsp file.redirectRandomOrderTo
= The type of randomization you are using"Users"
= The table you are going to save the pages the participant has visited"RandomPageOrder"
= The column in the table you are going to save the pages the participant has visited.New String
= In this case, it tells the survey manager to randomize the pages listed next.page1.jsp, page2.jsp, page3.jsp
= The pages you are randomizingNext page
= The page that participants will be pointed to after they have visited all of the pages.doneWithSurvey.jsp
= The last page a participant will see. It conveniently has a link that starts the survey over for the next person. It could be ANY jsp page in your survey however.@include file ="survey_end.jsp
= Tells the survey manager that this is the end of a survey jsp file.
- Tip - Please note that jsp is very unforgiving, if a comma, or quote is missing or duplicated you will get an ugly error message complaining about what ever you missed, or wrongfully included. Luckily, it will usually provide some useful clues as to what is wrong. Make your changes, and re-upload, and test again if there are errors