/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods. * * @param request servlet request * @param response servlet response */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { pedidosDAO dao = new pedidosDAO(); String clavePedido = request.getParameter("clavePedido"); pedidoBean pedido = new pedidoBean(); pedido = dao.getPedido(clavePedido); String claveCliente = pedido.getClaveCliente(); String nombreCliente = pedido.getNombreEmpresa(); String FechaS = pedido.getFecha(); String detallesPedido = pedido.getDetallesPedido(); String fechaInicial = pedido.getFechaInicial(); String fechaFinal = pedido.getFechaFinal(); String noPedido = pedido.getNoPedido(); String tipoCambio = pedido.getTipoCambio(); String tiposIva = pedido.getTipoIva(); String tipoPedido = pedido.getTipoPedido(); List listaClientes = new ArrayList(); listaClientes = dao.getClientes(); String mensaje = ""; if (pedido.getClavePedido() == null) { mensaje = "¡Numero de pedido No encontrado!"; RequestDispatcher rdExito = request.getRequestDispatcher("/jsp/Pedido/cargaModificarPedido.jsp"); request.setAttribute("mensaje", mensaje); rdExito.forward(request, response); } else { RequestDispatcher rdExito = request.getRequestDispatcher("/jsp/Pedido/modificarPedido.jsp"); request.setAttribute("FechaS", FechaS); request.setAttribute("mensaje", mensaje); request.setAttribute("clavePedido", clavePedido); request.setAttribute("claveCliente", claveCliente); request.setAttribute("nombreCliente", nombreCliente); request.setAttribute("detallesPedido", detallesPedido); request.setAttribute("fechaFinal", fechaFinal); request.setAttribute("noPedido", noPedido); request.setAttribute("tipoCambio", tipoCambio); request.setAttribute("tiposIva", tiposIva); request.setAttribute("tipoPedido", tipoPedido); request.setAttribute("listaClientes", listaClientes); request.setAttribute("fechaInicial", fechaInicial); rdExito.forward(request, response); } }
@Override public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { // HttpSession sesh = request.getSession(); // int id = 0; // id = (Integer) sesh.getAttribute("id"); // if (id != 0) { RequestDispatcher dis = request.getRequestDispatcher("search.jsp"); dis.forward(request, response); // } // else { // RequestDispatcher dis = request.getRequestDispatcher("login.jsp"); // dis.forward(request, response); // } }
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // retrieving values from input fields of matrixinput.jsp String sMatrix1 = request.getParameter("firstMatrix"); String sMatrix2 = request.getParameter("secondMatrix"); // Creating MatrixMultipler object MatrixMultiplier mm = new MatrixMultiplier(); // Passing Strings to convertToObject() method of MatrixMultiplier // convertToObject() is used to convert strings into MatrixBean MatrixBean fMatrix = mm.convertToObject(sMatrix1); MatrixBean sMatrix = mm.convertToObject(sMatrix2); // passing MatrixBean’s objects to multiply() method of // MatrixMultiplier and receiving the product matrix in the form // of MatrixBean MatrixBean rMatrix = mm.multiply(fMatrix, sMatrix); // saving results in database mm.saveResult(rMatrix); // storing the product of matrices into request, so that it can be // retrieved on matrixresult.jsp request.setAttribute("product", rMatrix); // forwarding request to matrixresult.jsp RequestDispatcher rd = request.getRequestDispatcher("matrixresult.jsp"); rd.forward(request, response); } // end processRequest()
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.println("<br><h4>we are getting data</h4>"); String code = request.getParameter("code"); out.println("<br>code: " + code); out.println("<br>"); try { OAuthClientRequest requestOAuth = OAuthClientRequest.tokenLocation("https://graph.facebook.com/oauth/access_token") .setGrantType(GrantType.AUTHORIZATION_CODE) .setClientId(apiKey) .setClientSecret(secretKey) .setRedirectURI(redirectUri) .setCode(code) .buildBodyMessage(); OAuthClient oAuthClient = new OAuthClient(new URLConnectionClient()); GitHubTokenResponse oAuthResponse = oAuthClient.accessToken(requestOAuth, GitHubTokenResponse.class); accessToken = oAuthResponse.getAccessToken(); expiresIn = oAuthResponse.getExpiresIn(); } catch (OAuthSystemException ae) { ae.printStackTrace(); } catch (OAuthProblemException pe) { pe.printStackTrace(); } // out.println("<br>Access Token: " + accessToken); // out.println("<br>Expires In: " + expiresIn); try { FacebookClient facebookClient = new DefaultFacebookClient(accessToken); myFriends = facebookClient.fetchConnection("me/friends", User.class); myFeeds = facebookClient.fetchConnection("me/home", Post.class); for (User myFriend : myFriends.getData()) { f.add(myFriend.getName()); out.println("<br>id: " + myFriend.getId() + " Name: " + myFriend.getName()); } // out.println("<br>"); out.println("<br>f count: " + f.size()); } catch (FacebookException e) { e.printStackTrace(); } facebookDataBean fdb = new facebookDataBean(); fdb.setName("zishan ali khan"); HttpSession session = request.getSession(); if (session != null) { session.setAttribute("myfdb", fdb); session.setAttribute("yourFriends", f); session.setAttribute("feeds", myFeeds); RequestDispatcher view = request.getRequestDispatcher("result.jsp"); view.forward(request, response); f.clear(); // out.println("<br>I am in"); } else { // out.println("<br>Session Over"); } }
protected void login(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.getRequestDispatcher("/login.jsp").forward(request, response); }
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); ResultSet rs = null; try { // SET UP Context environment, to look for Data Pooling Resource Context initCtx = new InitialContext(); Context envCtx = (Context) initCtx.lookup("java:comp/env"); DataSource ds = (DataSource) envCtx.lookup("jdbc/TestDB"); Connection dbcon = ds.getConnection(); // ########### SEARCH INPUT PARAMETERS, EXECUTE search // ##################################################### Vector<String> params = new Vector<String>(); params.add(request.getParameter("fname")); params.add(request.getParameter("lname")); params.add(request.getParameter("title")); params.add(request.getParameter("year")); params.add(request.getParameter("director")); List<Movie> movies = new ArrayList<Movie>(); movies = SQLServices.getMovies(params.toArray(new String[params.size()]), dbcon); // ########## SET DEFAULT SESSION() PARAMETERS #################################### request.getSession().removeAttribute("movies"); request.getSession().removeAttribute("linkedListMovies"); request.getSession().removeAttribute("hasPaged"); request.getSession().setAttribute("hasPaged", "no"); request.getSession().setAttribute("movies", movies); request.getSession().setAttribute("currentIndex", "0"); request.getSession().setAttribute("defaultN", "5"); // ########## IF MOVIES FROM SEARCH NON-EMPTY ########################################### List<String> fields = Movie.fieldNames(); int count = 1; if (!movies.isEmpty()) { request.setAttribute("movies", movies); for (String field : fields) { request.setAttribute("f" + count++, field); } request.getRequestDispatcher("../movieList.jsp").forward(request, response); } else { out.println("<html><head><title>error</title></head>"); out.println("<body><h1>could not find any movies, try your search again.</h1>"); out.println("<p> we are terribly sorry, please go back. </p>"); out.println("<table border>"); out.println("</table>"); } dbcon.close(); } catch (SQLException ex) { while (ex != null) { System.out.println("SQL Exception: " + ex.getMessage()); ex = ex.getNextException(); } } catch (java.lang.Exception ex) { out.println( "<html>" + "<head><title>" + "moviedb: error" + "</title></head>\n<body>" + "<p>SQL error in doGet: " + ex.getMessage() + "</p></body></html>"); return; } out.close(); }