List of usage examples for javax.servlet.http HttpServletRequest getRequestDispatcher
public RequestDispatcher getRequestDispatcher(String path);
From source file:cn.itcast.bbs.controller.BbsServlet.java
private void showAllType(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try {/* ww w.j av a 2 s . co m*/ List<Type> typeList = service.findAllType(); List<Type> typeListOrder = service.findAllTypeByClick(); request.setAttribute("typeList", typeList); request.setAttribute("typeListOrder", typeListOrder); request.getRequestDispatcher("/WEB-INF/bbs/listAllType.jsp").forward(request, response); } catch (Exception e) { e.printStackTrace(); request.setAttribute("message", "??"); request.getRequestDispatcher("/WEB-INF/bbs/message.jsp").forward(request, response); } }
From source file:com.tenduke.example.scribeoauth.oauth2.OAuth20CallbackServlet.java
/** * <p>/*from ww w. ja v a 2s. c o m*/ * Proesses requests for both HTTP <code>GET</code> and <code>POST</code> methods. * </p> * <p> * Expects request parameter named "code", which is used for making access token request to provider. * </p> * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ private void processRequest(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException { // String verifier = request.getParameter("code"); // OAuth20Provider provider = new OAuth20Provider(oauthConfig); OAuthService service = new ServiceBuilder().provider(provider).apiKey(provider.getApiKey()) .apiSecret(provider.getApiSecret()).callback(provider.getCallbackUrl()).build(); // Token accessToken = service.getAccessToken(OAuthConstants.EMPTY_TOKEN, new Verifier(verifier)); if (accessToken == null) { // request.getRequestDispatcher("/unauthorized.jsp").forward(request, response); } else { // JSONObject userInfo = graphMe(accessToken, provider); doLogin(request, response, userInfo); // request.setAttribute("isOauth20", true); request.setAttribute("userInfo", userInfo); if (service instanceof IdTokenOauth20Service) { // request.setAttribute("id_token", ((IdTokenOauth20Service) service).getIdToken()); } // request.getRequestDispatcher("/welcomeIn.jsp").forward(request, response); } }
From source file:net.incrementalism.tooter.LogInServlet.java
@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { if (isBlank(request.getParameter("userName"))) { request.setAttribute("error", "'User Name' must not be empty."); } else if (isBlank(request.getParameter("password"))) { request.setAttribute("error", "'Password' must not be empty."); } else {//from w w w . jav a 2 s. c o m try { setCurrentUser(request, logInUser(request.getParameter("userName"), request.getParameter("password"))); response.sendRedirect("/profile"); return; } catch (LogInException e) { request.setAttribute("error", "Incorrect User Name or Password."); } } request.getRequestDispatcher("/logIn.jsp").include(request, response); }
From source file:io.muic.ooc.webapp.servlet.RegisterServlet.java
@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String iusername = request.getParameter("username"); String ipassword = request.getParameter("password"); String ifirstname = request.getParameter("fname"); if (!StringUtils.isBlank(iusername) && !StringUtils.isBlank(ipassword) && !StringUtils.isBlank(ifirstname)) { if (!db.readData().containsKey(iusername)) { db.insertDB(iusername, ipassword, ifirstname); response.sendRedirect("/login"); } else {/*from ww w. j av a 2 s . com*/ String error = "Please choose another username. "; request.setAttribute("error", error); RequestDispatcher rd = request.getRequestDispatcher("WEB-INF/signup.jsp"); rd.include(request, response); } } else { String error = "Please fill in all the requirement form."; request.setAttribute("error", error); RequestDispatcher rd = request.getRequestDispatcher("WEB-INF/signup.jsp"); rd.include(request, response); } }
From source file:cz.muni.fi.myweb1.RestaurantServlet.java
@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String name = request.getAttribute("username").toString(); String password = request.getAttribute("password").toString(); /* /*from w w w.jav a2 s . c o m*/ response.setContentType("text/html;charset=utf-8"); PrintWriter out = response.getWriter(); out.println("<h1>Text</h1><pre>generated directly from servlet code"); out.println("serverInfo=" + getServletContext().getServerInfo()); out.println("parameters: "+ name + " " + password); */ if (loginFacade.login(name, password)) { request.getSession().setAttribute("username", name); RequestDispatcher rd = request.getRequestDispatcher("/outline.jsp"); rd.forward(request, response); } else { //TODO error } /* try { List<Restaurant> list = myFacade.topRestaurants(); request.getSession().setAttribute("restList", list); RequestDispatcher rd=request.getRequestDispatcher("/outline.jsp"); rd.forward(request, response); } catch (Exception e) { response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage()); } */ }
From source file:br.unicamp.cotuca.dpd.pd12.acinet.vagalmail.servlet.Configuracoes.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setCharacterEncoding("UTF-8"); request.setCharacterEncoding("UTF-8"); String metodo = "", req = request.getRequestURI(); if (req.contains("/nova")) { metodo = "nova"; } else if (req.contains("/conta")) { metodo = "conta"; } else if (req.contains("/senha")) { metodo = "senha"; } else {//from w w w . ja v a2 s .co m response.sendRedirect("/conf/conta"); } if (!"".equals(metodo)) request.getRequestDispatcher("/conf.jsp?metodo=" + metodo).include(request, response); }
From source file:com.alfaariss.oa.authentication.remote.saml2.profile.re.ResponseEndpoint.java
private void forwardToSSOWeb(HttpServletRequest request, HttpServletResponse response, ISession session) throws OAException { try {/*from ww w . j a v a 2s . com*/ request.setAttribute(ISession.ID_NAME, session); RequestDispatcher oDispatcher = request.getRequestDispatcher(_sWebSSOPath); if (oDispatcher == null) { _logger.warn("There is no requestor dispatcher supported with name: " + _sWebSSOPath); throw new OAException(SystemErrors.ERROR_INTERNAL); } oDispatcher.forward(request, response); } catch (OAException e) { throw e; } catch (Exception e) { _logger.fatal("Internal error during forward to sso web", e); throw new OAException(SystemErrors.ERROR_INTERNAL); } }
From source file:com.netcracker.financeapp.controller.bank_card.BankCardAddServlet.java
@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String cardNumber = request.getParameter("cardNumber"); int amount = Integer.parseInt(request.getParameter("currentAmount")); int cvv = Integer.parseInt(request.getParameter("cvv")); String ownerName = request.getParameter("ownerName"); String ownerSurname = request.getParameter("ownerSurname"); int expireMonth = Integer.parseInt(request.getParameter("expireMonth")); int expireYear = Integer.parseInt(request.getParameter("expireYear")); int cardId = bankCardService.insertBankCard(amount, cvv, expireMonth, expireYear, cardNumber, ownerName, ownerSurname);//from w w w . jav a2s. co m if (cardId > 0) { request.getRequestDispatcher("templates/success.jsp").forward(request, response); } else { request.getRequestDispatcher("templates/error.jsp").forward(request, response); } }
From source file:io.muic.ooc.webapp.servlet.SignupServlet.java
@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { UserService userService = new UserService(); String username = request.getParameter("username"); String password = request.getParameter("password"); String name = request.getParameter("name"); Connection conn = userService.connectSQL(); System.out.println("SignupServlet"); boolean userExist = userService.userExist(conn, username); if (StringUtils.isBlank(username) || StringUtils.isBlank(password) || StringUtils.isBlank(name)) { String error = "Please don't leave any blank field!"; request.setAttribute("error", error); RequestDispatcher rd = request.getRequestDispatcher("WEB-INF/signup.jsp"); rd.include(request, response);/*from w w w. j a va 2 s .c o m*/ } else if (!userExist) { /* For posting user information */ String info1 = "Your id is: " + LoginServlet.currentUserID; String info2 = "Your name is: " + LoginServlet.currentUserName; request.setAttribute("info1", info1); request.setAttribute("info2", info2); /* Ends here */ userService.createUser(conn, username, password, name); RequestDispatcher rd = request.getRequestDispatcher("WEB-INF/home.jsp"); rd.include(request, response); } else { String error = "This username already exists, please choose another"; request.setAttribute("error", error); RequestDispatcher rd = request.getRequestDispatcher("WEB-INF/signup.jsp"); rd.include(request, response); } }
From source file:com.tenduke.example.webadmin.oauth2.OAuth20CallbackServlet.java
/** * <p>/*w w w . ja v a 2 s. c o m*/ * Proesses requests for both HTTP <code>GET</code> and <code>POST</code> methods. * </p> * <p> * Expects request parameter named "code", which is used for making access token request to provider. * </p> * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ private void processRequest(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException { // String verifier = request.getParameter("code"); // OAuth20Provider provider = new OAuth20Provider(oauthConfig); OAuthService service = new ServiceBuilder().provider(provider).apiKey(provider.getApiKey()) .apiSecret(provider.getApiSecret()).callback(provider.getCallbackUrl()).build(); // Token accessToken = service.getAccessToken(OAuthConstants.EMPTY_TOKEN, new Verifier(verifier)); if (accessToken == null) { // request.getRequestDispatcher("/unauthorized.jsp").forward(request, response); } else { // JSONObject userInfo = graphMe(accessToken, provider); SessionInformation sessionInformation = doLogin(request, response, userInfo); sessionInformation.setAccessToken(accessToken); // request.setAttribute("isOauth20", true); request.setAttribute("userInfo", userInfo); if (service instanceof IdTokenOauth20Service) { // sessionInformation.setIdToken(((IdTokenOauth20Service) service).getIdToken()); request.setAttribute("id_token", ((IdTokenOauth20Service) service).getIdToken()); } // RequestUrl requestUrl = new RequestUrl(request); response.sendRedirect(requestUrl.getSchemeHostAndPort() + requestUrl.getContextPath()); } }