📄 jspdispatcherservlet.java
字号:
/*
* Copyright (c) 2003-2004, Alexander Greif
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the Flow4J-Eclipse project nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.orthanc.flow4j.runtime.web.servlet;
import java.io.IOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import net.orthanc.flow4j.runtime.Flow4JRuntimeConsts;
import net.orthanc.flow4j.runtime.web.WebFlowDictionary;
/**
* Class JSPDispatcherServlet first executes the flow that weas specified in the
* ULI path info, and then dispatches the request to the resource that is returned by a
* template flowlet at the end of the flow.
* The resource can be dynamic, or static.
* @author agreif
*
*/
public class JSPDispatcherServlet extends FlowDispatcherServlet {
/**
* Executes the flow in the superclass and then
* the request is dispatched to the resource that is returned by a
* template flowlet at the end of the flow.
* The resource can be dynamic, or static.
* @see net.orthanc.flow4j.runtime.web.servlet.FlowDispatcherServlet#postFlowExecution(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, net.orthanc.flow4j.runtime.web.WebFlowDictionary)
*/
protected void postFlowExecution(
HttpServletRequest req,
HttpServletResponse res,
WebFlowDictionary dictionary) throws Flow4JServletException {
// TODO Auto-generated method stub
super.postFlowExecution(req, res, dictionary);
// determine template name
String templateName =
(String) dictionary.get(Flow4JRuntimeConsts.DICT_KEY_TEMPLATE_NAME);
if (templateName == null)
throw new Flow4JServletException("No template specified");
// forward request
StringBuffer forwardPath = new StringBuffer();
if (!templateName.startsWith("/"))
forwardPath.append("/");
forwardPath.append(templateName);
try {
forward(req, res, forwardPath.toString());
} catch (Exception e) {
throw new Flow4JServletException("could not forward request to: " + forwardPath, e);
}
}
/**
* Forwards the request to the given resource.
*/
private void forward(
HttpServletRequest req,
HttpServletResponse res,
String forwardPath)
throws IOException, ServletException {
// Create a RequestDispatcher the corresponding resource
RequestDispatcher rd =
getServletContext().getRequestDispatcher(forwardPath);
if (rd == null)
throw new Flow4JServletException(
"Cannot forward to: " + forwardPath);
// Forward control to the specified resource
rd.forward(req, res);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -