use of javax.servlet.RequestDispatcher in project tutorials by eugenp.
the class WelcomeServlet method doGet.
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
CookieReader cookieReader = new CookieReader(request);
Optional<String> uiColor = cookieReader.readCookie("uiColor");
Optional<String> userName = cookieReader.readCookie("userName");
if (!userName.isPresent()) {
response.sendRedirect("/login");
} else {
request.setAttribute("uiColor", uiColor.orElse("blue"));
request.setAttribute("userName", userName.get());
request.setAttribute("sessionAttribute", request.getSession().getAttribute("sampleKey"));
RequestDispatcher dispatcher = request.getRequestDispatcher("/WEB-INF/jsp/welcome.jsp");
dispatcher.forward(request, response);
}
}
use of javax.servlet.RequestDispatcher in project tutorials by eugenp.
the class FrontCommand method forward.
public void forward(String target) throws ServletException, IOException {
if (intercept) {
return;
}
String path = String.format("/WEB-INF/jsp/%s.jsp", target);
RequestDispatcher dispatcher = request.getServletContext().getRequestDispatcher(path);
dispatcher.forward(request, response);
}
use of javax.servlet.RequestDispatcher in project sonar-java by SonarSource.
the class PerformForward method handleAsInclude.
private void handleAsInclude(String uri, ServletContext servletContext, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
RequestDispatcher rd = servletContext.getRequestDispatcher(uri);
if (rd == null) {
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Error getting RequestDispatcher for " + uri);
return;
}
if (LOG.isDebugEnabled()) {
LOG.debug("Including " + uri);
}
rd.include(request, response);
}
use of javax.servlet.RequestDispatcher in project sonar-java by SonarSource.
the class RequestProcessor method doInclude.
/**
* <p>Do an include of specified URI using a <code>RequestDispatcher</code>.
* This method is used by all internal method needing to do an
* include.</p>
*
* @param uri Context-relative URI to include
* @param request Current page request
* @param response Current page response
* @throws IOException if an input/output error occurs
* @throws ServletException if a servlet exception occurs
* @since Struts 1.1
*/
protected void doInclude(String uri, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
RequestDispatcher rd = getServletContext().getRequestDispatcher(uri);
if (rd == null) {
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, getInternal().getMessage("requestDispatcher", uri));
return;
}
rd.include(request, response);
}
use of javax.servlet.RequestDispatcher in project evosuite by EvoSuite.
the class EvoServletContext method createDispatcher.
// ------------ EvoSuite test methods -----------------
public void createDispatcher(String name) {
if (name == null || name.trim().isEmpty()) {
// do nothing
return;
}
RequestDispatcher dis = new EvoRequestDispatcher(name);
dispatchers.put(name, dis);
TestDataJavaEE.getInstance().accessedDispatcher(name);
}
Aggregations