Sample 26015: How to Create a JSP Remote File Selector
Overview
This sample shows a JSP RemoteFileSelector connecting to data via a SAS® Foundation Services connection, which involves creating an InformationServicesSelector. The InformationServicesSelector is a specific implementation of the RemoteFileSelector that is used to access repository data through Information Services.
This sample demonstrates how to display the remote file selector, but it does not demonstrate how to use it to open content. For an example of using the selector in order to open specific content in a viewer, look at the SAS AppDev Studio templates Report Viewer Servlet(Uses SAS Web Report Viewer) or Information Map Viewer Servlet(Uses SAS Visual Data Explorer).
Here are the steps for creating a simple InformationServicesSelector:
- Create a InformationServicesSelector.
- Access your repository instance.
- Render the InformationServicesSelector.
The sample is based on the Information Map Default Servlet template, which is available in SAS® AppDev Studio. The Full Code tab in this sample contains instructions for modifying the template project.
Additional Documentation
- For a list of samples for common tasks, see SAS Note 32218.
- The SAS AppDev Studio Developer's Site contains detailed information that will assist you when developing Web applications with SAS AppDev Studio, including an API reference and the custom tag reference for the sas tagset.
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
Instructions
- Build a new Web application project in SAS AppDev Studio by using the Information Map Default Servlet template.
- The template will generate a servlet and a JSP file, which, by default, are named InfoMapViewerExampleControllerServlet.java and InfoMapViewerExampleViewer.jsp. Replace the contents of these files with the code below.
- Execute the servlet on the test Tomcat server.
Tip: For help with building a Web application project and testing a Web application, see SAS Note 32218.
Code for InfoMapDefaultExampleViewer.jsp
<%@ page pageEncoding="UTF-8"%>
<html>
<head>
<link href="styles/sasComponents.css" rel="STYLESHEET" type="text/css">
</head>
<body>
<jsp:useBean id="sas_informationSelector" scope="session"
type="com.sas.servlet.tbeans.remotefileselector2.html.InformationServicesSelector"/>
<%
sas_informationSelector.setRequest(request);
sas_informationSelector.setResponse(response);
sas_informationSelector.write(out);
%>
</body>
</html>
|
Code for InfoMapViewerExampleControllerServlet.java
Required changes
- If you did not use the default values during the generation of the project, you might need to update the following values.
- The package for the servlet.
package servlets;
- The servlet name.
public class InfoMapViewerExampleControllerServlet ...
- The URL mapping for the action providerk, whichmust match the servlet mapping for the servlet.
sas_actionProvider.setControllerURL(request.getContextPath()+ "/InfoMapViewerExample");
package servlets;
import java.io.IOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import listeners.ExamplesSessionBindingListener;
import com.sas.actionprovider.HttpActionProvider;
import com.sas.services.discovery.DiscoveryService;
import com.sas.services.discovery.DiscoveryServiceInterface;
import com.sas.services.discovery.ServiceTemplate;
import com.sas.services.session.SessionContextInterface;
import com.sas.services.session.SessionServiceInterface;
import com.sas.services.user.UserContextInterface;
import com.sas.services.user.UserServiceInterface;
import com.sas.servlet.tbeans.remotefileselector2.html.InformationServicesSelector;
import com.sas.servlet.util.BaseUtil;
import com.sas.web.keys.ComponentKeys;
public class InfoMapDefaultExampleControllerServlet extends
javax.servlet.http.HttpServlet {
// Declare a default version ID since parent class implements
// java.io.Serializable
private static final long serialVersionUID = 1L;
// Global webapp Strings
private static final String ACTION_PROVIDER = "sas_actionProvider";
// Global webapp InfoMap variables
private static final String INFORMATION_SELECTOR = "sas_informationSelector";
/*
* doPost() Respond to the Post message.
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// Note: Calling doGet to provide same behavior to POST and GET HTTP
// methods.
doGet(request, response);
}
/*
* doGet() Respond to the Get message.
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// Note: Add User DO_GET code here
HttpSession session = request.getSession();
// Ensure character set is specified before calling
// response.getWriter().
String charset = BaseUtil.getOutputCharacterEncoding(request);
response.setContentType("text/html; charset=" + charset);
// Setup the ActionProvider
HttpActionProvider sas_actionProvider = null;
synchronized (session) {
if (session != null) {
sas_actionProvider = (HttpActionProvider) session
.getAttribute(ACTION_PROVIDER);
}
// if ActionProvider is null, create one and put it on the session
if (sas_actionProvider == null) {
sas_actionProvider = new HttpActionProvider();
sas_actionProvider.setLocale(request.getLocale());
sas_actionProvider.setControllerURL(request.getContextPath()
+ "/InfoMapDefaultExample");
sas_actionProvider.setName(ACTION_PROVIDER);
// store object in its scope
if (session != null)
session.setAttribute(ACTION_PROVIDER, sas_actionProvider);
}
// else execute the ActionProvider command
else {
sas_actionProvider.executeCommand(request, response, response
.getWriter());
}
}
synchronized (session) {
InformationServicesSelector sas_informationSelector = null;
if (session != null) {
sas_informationSelector = (InformationServicesSelector) session
.getAttribute(INFORMATION_SELECTOR);
} // end of if session is not null
if (sas_informationSelector == null) {
try {
// Obtain the local discovery service
DiscoveryServiceInterface discoveryService = DiscoveryService
.defaultInstance();
// Use the discovery services to find a user service.
UserServiceInterface userService = (UserServiceInterface) discoveryService
.findService(new ServiceTemplate(
new Class[] { UserServiceInterface.class }));
// Get a user context from the user service by logging in.
// The initial parameters are obtained from the web.xml
// file.
// Note: A password must be set in the web.xml file.
ServletConfig sc = getServletConfig();
String domain = sc.getInitParameter("metadata-domain");
String username = sc.getInitParameter("metadata-userid");
String password = sc.getInitParameter("metadata-password");
UserContextInterface userContext = userService.newUser(
username, password, domain);
if (session != null) {
ExamplesSessionBindingListener.getInstance(session)
.addUserContext(userContext);
}
// Use the discovery services to find a session service.
SessionServiceInterface sessionService = (SessionServiceInterface) discoveryService
.findService(new ServiceTemplate(
new Class[] { SessionServiceInterface.class }));
// Create a session for this user and bind it to the user
// context.
SessionContextInterface sessionContext = sessionService
.newSessionContext(userContext);
userContext.setSessionContext(sessionContext);
if (session != null) {
ExamplesSessionBindingListener.getInstance(session)
.addSessionContext(sessionContext,
"InfoMapDefaultExample_lock");
}
// Create a new InformationServicesSelector and store it on
// the session
sas_informationSelector = new InformationServicesSelector(
userContext, null, null);
sas_informationSelector
.setActionProvider(sas_actionProvider);
if (session != null) {
session.setAttribute(INFORMATION_SELECTOR,
sas_informationSelector);
}
} catch (Exception e) {
throw new ServletException(e);
}
}
}
// Forward the request to the JSP for display
String sas_forwardLocation = request
.getParameter(ComponentKeys.FORWARD_LOCATION);
if (sas_forwardLocation == null) {
sas_forwardLocation = "/InfoMapDefaultExampleViewer.jsp";
}
RequestDispatcher rd = getServletContext().getRequestDispatcher(
sas_forwardLocation);
rd.forward(request, response);
}
}
|
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.

This sample shows how to create a RemoteFileSelector, which is used to navigate and select directories and entries on a server.
| Date Modified: | 2008-07-29 10:05:47 |
| Date Created: | 2006-01-30 15:45:17 |
Operating System and Release Information
| SAS System | SAS AppDev Studio | Microsoft Windows 2000 Server | 3.2 | | 9.1 TS1M3 SP4 | |
| Microsoft Windows XP Professional | 3.2 | | 9.1 TS1M3 SP4 | |
| Microsoft Windows Server 2003 Standard Edition | 3.2 | | 9.1 TS1M3 SP4 | |
| Microsoft Windows Server 2003 Enterprise Edition | 3.2 | | 9.1 TS1M3 SP4 | |
| Microsoft Windows Server 2003 Datacenter Edition | 3.2 | | 9.1 TS1M3 SP4 | |
| Microsoft Windows NT Workstation | 3.2 | | 9.1 TS1M3 SP4 | |
| Microsoft Windows 2000 Professional | 3.2 | | 9.1 TS1M3 SP4 | |
| Microsoft® Windows® for x64 | 3.2 | | 9.1 TS1M3 SP4 | |
| Microsoft Windows 2000 Advanced Server | 3.2 | | 9.1 TS1M3 SP4 | |
| Microsoft Windows 2000 Datacenter Server | 3.2 | | 9.1 TS1M3 SP4 | |
| Windows Vista | 3.2 | | 9.1 TS1M3 SP4 | |