<%@page contentType="text/html;charset=UTF-8" %> ViewsFlash questionnaire embedded in JSP page <% /** * The example used here uses a cookie named ViewsFlash to authenticate respondnents. * Because an include cannot reliably set a cookie, * the cookie is set here: */ Cookie [] cookies = request.getCookies(); boolean bHasCookie = false; for ( int k = 0 ; ! bHasCookie && cookies != null && k < cookies.length; k++ ) { if ( cookies [k].getName().equalsIgnoreCase("ViewsFlash") ) bHasCookie = true; } if ( ! bHasCookie ) { String me = String.valueOf(System.currentTimeMillis()); Cookie viewsflashcookie = new Cookie ( "ViewsFlash", me ); response.addCookie(viewsflashcookie); } /* // This is necessary if the JSP page is not in /ViewsFlash web application context // It may require enabling CrossContext=true in server.xml if running on Tomcat, like this: // ServletContext scx = application.getContext ("/ViewsFlash"); if ( scx == null ) { out.print ("application.getContext (\"/ViewsFlash\") failed -- check crossContext application server settings"); return; } */ // Use this only when the JSP page is in the ViewsFlash context // If it is not, use application.getContext as described above ServletContext scx = this.getServletConfig().getServletContext(); // /servlet/viewsflash is the ViewsFlash servlet for accepting questionnaire responses // The query string begins after the ? // outputtorequestattribute=content means don't send the output to the response output stream, // but rather compose it as a String and leave it in a request attribute named "content" String ViewsFlashServlet = "/servlet/viewsflash?outputtorequestattribute=content"; // On initial page, determine what questionnaire to show String ID = request.getParameter("questionnaire"); if ( ID == null ) ID = "Examples!Service"; // Add additional parameters to the query string // pollid is the parameter used to pass the questionnaire ID, eg Examples!Service String url = ViewsFlashServlet; // On page 2 and following of a questionnaire, pollid will already be set String pollid = request.getParameter("pollid"); if ( pollid == null ) { url += "&pollid=" + ID; pollid = ID; } // On page 2 and following of a questionnaire, cmdwill already be set String cmd = request.getParameter("cmd"); if ( cmd == null ) url += "&cmd=page"; // On the initial entry to this page, cmd=page and pollid= will be set // allalphapollid is used in the
tag String allalphapollid = pollid; int ibang = allalphapollid.indexOf ('!'); if ( ibang > 0 ) { allalphapollid = pollid.substring ( 0,ibang ) + pollid.substring (ibang+1); } // tells ViewsFlash to omit sections and tags like which are provided by this JSP request.setAttribute ("com.cogix.vwf.isportal", "true"); /** * if the questionnaire uses Basic (J2EE) authentication or cookie authentication, * the necessary information is already in the request. * If the questionnaire uses Portal authentication, * add code like the following: * * String userid = "The authenticated user id from wherever it comes"; * request.setAttribute ("com.cogix.vwf.getremoteuser",userid); */ // include ViewsFlash; equivalent to http://..../ViewsFlash/servlet/viewsflash?cmd=page&pollid=... RequestDispatcher rd = scx.getRequestDispatcher (url); rd.include(request,response); // ViewsFlash returns content in request attribute named // "content" as requested in outputtorequestattribute=content above String content = (String) request.getAttribute("content"); // Use < % = content % > to display questionnaire content %>
Cogix ViewsFlash questionnaire embedded in a JSP page
Left side nav bar
The embedded questionnaire here: <%=content%>