Java Code Examples for javax.servlet.http.HttpServletRequest.getRequestDispatcher()

The following are Jave code examples for showing how to use getRequestDispatcher() of the javax.servlet.http.HttpServletRequest class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: LojaDeInstrumentosMusicais   File: ConsultaProdutosVendaServlet.java   View Source Code Vote up 6 votes
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    HttpSession sessao = request.getSession();
    ArrayList<Produto> Lista = new ArrayList();
    ServicoProduto sc = new ServicoProduto();
    String codigoempresa = (String) sessao.getAttribute("Empresa");

    try {
        Lista = (ArrayList<Produto>) sc.procurarProduto(codigoempresa, Integer.parseInt(codigoempresa));
    } catch (Exception e) {

    }

    sessao.setAttribute("ListaProduto", Lista);

    RequestDispatcher dispatcher
            = request.getRequestDispatcher("/venda.jsp");
    dispatcher.forward(request, response);

}
 
Example 2
Project: redesocial   File: CategoriaControle.java   View Source Code Vote up 6 votes
private void editar(HttpServletRequest request, HttpServletResponse response) throws Exception{
    try {
        Integer id = Integer.parseInt(request.getParameter("id"));

        CategoriaBO categoriaBO = new CategoriaBO();
        Categoria categoria = categoriaBO.selecionar(id);

        request.setAttribute("categoria", categoria);

        request.setAttribute("mensagem", "Registro selecionado com sucesso");
    } catch (Exception ex){
        request.setAttribute("erro", ex.getMessage());
    }

    RequestDispatcher rd = request.getRequestDispatcher("paginas/categorias/cadastro.jsp");
    rd.forward(request, response);
}
 
Example 3
Project: ChemistryAdministrativePortal   File: AddCourseServlet.java   View Source Code Vote up 6 votes
/**
 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
 */
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	
	// get the data
		String name = request.getParameter("name");
		String title = request.getParameter("title");
		String credits = request.getParameter("credits"); 
		String division= request.getParameter("division");
		
		
		
		// set up a Course object
		Course course = new Course(name, title, credits, division);
		
		// set up an addQuery object
		AddQuery aq = new AddQuery("chemistrydatabase", "root", "root");   //Removed password for security reasons
		
		// pass the Course to addQuery to add to the database
		aq.doAddCourse(course);
		
		// pass the execution control to the ReadServlet
		String url = "/CourseServlet";
		
		RequestDispatcher dispatcher = request.getRequestDispatcher(url);
		dispatcher.forward(request, response);
}
 
Example 4
Project: redesocial   File: TiposAtividadesControle.java   View Source Code Vote up 6 votes
/**
 * Cadastra uma atividade no banco de dados
 * @param request
 * @param response
 * @throws Exception
 */
private void cadastrar(HttpServletRequest request, HttpServletResponse response) throws Exception{
    TiposAtividades tiposAtividades = new TiposAtividades ();

    if (!"".equals(request.getParameter("id").trim())){
        tiposAtividades.setId(Integer.parseInt(request.getParameter("id")));
    }

    tiposAtividades.setNome(request.getParameter("nome"));
    

    request.setAttribute("nome", tiposAtividades);

    if (tiposAtividades.getId() == null){
        this.inserir(tiposAtividades, request, response);
    } else {
        this.alterar(tiposAtividades, request, response);
    }
    
    RequestDispatcher rd = request.getRequestDispatcher("paginas/tiposAtividades.jsp");
    rd.forward(request, response);
}
 
Example 5
Project: redesocial   File: ArtigoControle.java   View Source Code Vote up 5 votes
private void cadastrar(HttpServletRequest request, HttpServletResponse response) throws Exception{
    Artigo artigo = new Artigo();

    if (!"".equals(request.getParameter("id").trim())){
        artigo.setId(Integer.parseInt(request.getParameter("id")));
    }

    artigo.setIdioma(request.getParameter("idioma"));
    artigo.setRevista(request.getParameter("revista"));
    artigo.setISSN(request.getParameter("issn"));
    
    artigo.setData(new Date());
    
    artigo.setAreaConhecimento(request.getParameter("area_conhecimento"));
    artigo.setTitulo(request.getParameter("titulo"));
    artigo.setResumo(request.getParameter("resumo"));
    artigo.setURL(request.getParameter("url"));
    artigo.setArtigo(new byte[]{});
    
    int idCategoria = Integer.parseInt( request.getParameter("categoria") );
    CategoriaBO categoriaBO = new CategoriaBO();
    Categoria categoria = categoriaBO.selecionar(idCategoria);
    artigo.setCategoria(categoria);

    request.setAttribute("artigo", artigo);
    
    List categorias = categoriaBO.listar();            
    request.setAttribute("categorias", categorias);

    if (artigo.getId() == null){
        this.inserir(artigo, request, response);
    } else {
        this.alterar(artigo, request, response);
    }

    RequestDispatcher rd = request.getRequestDispatcher("paginas/artigos/cadastro.jsp");
    rd.forward(request, response);
}
 
Example 6
Project: mm-system-2017   File: ForwardPath.java   View Source Code Vote up 5 votes
/**
 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
 */
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	 String path = request.getParameter("jsp");
	 String switchPath="LogIn.jsp";
	/* switch(path) {
	 case ("welcome.jsp"): switchPath=path;
	 case (""):
	//this change is done by Daniel, sorry if I ruined something, trying to increase security 
	 }*/
	 RequestDispatcher req=request.getRequestDispatcher("Home.jsp");
	 req.forward(request, response);	   
}
 
Example 7
Project: Projeto_Integrador_3_Semestre   File: CadastroHotelServlet.java   View Source Code Vote up 5 votes
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    RequestDispatcher dispatcher = request.getRequestDispatcher("WEB-INF/jsp/CadastroHotel.jsp");
    dispatcher.forward(request, response);
}
 
Example 8
Project: Projeto_Integrador_3_Semestre   File: CadastroHotelServlet.java   View Source Code Vote up 5 votes
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    HotelService service = new HotelService();
    HotelDAO dao = new HotelDAO();

    RelatorioDAO relatorioDAO = new RelatorioDAO();
    RelatorioMudancas relatorio = new RelatorioMudancas();

    String nome_hotel = request.getParameter("nome_hotel");
    String data_entrada = request.getParameter("data_entrada");
    String data_saida = request.getParameter("data_saida");
    int quantidade_quartos = Integer.parseInt(request.getParameter("quantidade_quartos"));
    int quantidade_hospedes = Integer.parseInt(request.getParameter("quantidade_hospedes"));
    float preco = Float.parseFloat(request.getParameter("preco"));

    request.setAttribute("erroNome_hotel", service.validaNome(nome_hotel));
    request.setAttribute("erroData_entrada", service.validaEntrada(data_entrada));
    request.setAttribute("erroData_saida", service.validaSaida(data_saida));
    request.setAttribute("erroQuantidade_quartos", service.validaQuantidade_quartos(quantidade_quartos));
    request.setAttribute("erroQuantidade_hospedes", service.validaQuantidade_hospedes(quantidade_hospedes));
    request.setAttribute("erroPreco", service.validaPreco(preco));

    Hotel hotel = new Hotel(nome_hotel.trim(), data_entrada.trim(), data_saida.trim(),
            quantidade_quartos, quantidade_hospedes, preco, true);

    if (service.validaHotel(nome_hotel, quantidade_quartos, data_entrada, data_saida, quantidade_hospedes, preco)) {
        RequestDispatcher dispatcher = request.getRequestDispatcher("WEB-INF/jsp/CadastroHotel.jsp");
        dispatcher.forward(request, response);
    } else {
        try {

            dao.inserir(hotel);
            HttpSession sessao = request.getSession();
            int identificacaoF = (int) sessao.getAttribute("id_func");
            relatorio.setId_func(identificacaoF);
            relatorio.setMudanca("Cadastro de hotel efetuado!");
            relatorioDAO.inserir(relatorio);
            response.sendRedirect(request.getContextPath() + "/inicio");

        } catch (Exception ex) {

            Logger.getLogger(CadastroHotelServlet.class.getName()).log(Level.SEVERE, null, ex);

        }
    }
}
 
Example 9
Project: LojaDeInstrumentosMusicais   File: AlterarProdutoServlet.java   View Source Code Vote up 5 votes
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
      RequestDispatcher dispatcher
 = request.getRequestDispatcher("/cadastroProduto.jsp");
dispatcher.forward(request, response);
}
 
Example 10
Project: central-medic-center   File: BookAppointment.java   View Source Code Vote up 5 votes
/**
 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
 *      response)
 */
protected void doPost(HttpServletRequest request, HttpServletResponse response)
		throws ServletException, IOException {

	HttpSession session;
	session = request.getSession();
	if (session.isNew()) {
		redirectToLogin(request, response);
	} else {
		Patient patient = new DatabaseHelper().getPatient((int) session.getAttribute("UserID"));
		Appointment appointment = new Appointment(patient, (String) request.getParameter("symptons"),
				(String) request.getParameter("disease"),
				DateUtils.getLongFromDate((String) request.getParameter("preferredDate")),
				(String)request.getParameter("title"));


		// insert in DB
		int status = new DatabaseHelper().createAppointment(appointment);
		if (status > 0) {
			// successfully inserted
			// redirect to patient dashboard
			RequestDispatcher rs;
			rs = request.getRequestDispatcher("patient");
			request.setAttribute("personId", appointment.getPatient().getId());
			rs.forward(request, response);
		} else {
			// error 
			//redirect to login
			redirectToLogin(request, response);
		}
	}
}
 
Example 11
Project: 112016.pizzeria-app   File: UpdateClientController.java   View Source Code Vote up 5 votes
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException {
	
	Integer id = Integer.parseInt(req.getParameter("id"));
	Client c = clientService.retrieveClient(id);
	req.setAttribute("client", c);

	RequestDispatcher dispatcher = req.getRequestDispatcher(VUE_UPDATE_CLIENT);
	dispatcher.forward(req, resp);

}
 
Example 12
Project: central-medic-center   File: CloseAppointment.java   View Source Code Vote up 4 votes
private void redirectToLogin(HttpServletRequest request, HttpServletResponse response)
		throws ServletException, IOException {
	RequestDispatcher rs = request.getRequestDispatcher("login.jsp");
	request.setAttribute("error", "Please login again");
	rs.forward(request, response);
}
 
Example 13
Project: the-vigilantes   File: RessurserM12.java   View Source Code Vote up 3 votes
/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    RequestDispatcher rd = request.getRequestDispatcher("JSP/RessurserM12.jsp");
        rd.include(request, response);    
}
 
Example 14
Project: the-vigilantes   File: RessurserM2.java   View Source Code Vote up 3 votes
/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    RequestDispatcher rd = request.getRequestDispatcher("JSP/RessurserM2.jsp");
        rd.include(request, response);    
}
 
Example 15
Project: the-vigilantes   File: DeleteUser.java   View Source Code Vote up 3 votes
/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    try (PrintWriter out = response.getWriter()) {
        RequestDispatcher rd = request.getRequestDispatcher("JSP/DeleteUser.jsp");
            rd.forward(request, response);
    }
}
 
Example 16
Project: the-vigilantes   File: Sok.java   View Source Code Vote up 3 votes
/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    try (PrintWriter out = response.getWriter()) {
        RequestDispatcher rd = request.getRequestDispatcher("JSP/sok.jsp");
            rd.forward(request, response);
    }
}
 
Example 17
Project: the-vigilantes   File: RessurserM11.java   View Source Code Vote up 3 votes
/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    RequestDispatcher rd = request.getRequestDispatcher("JSP/RessurserM11.jsp");
        rd.include(request, response);    
}
 
Example 18
Project: the-vigilantes   File: RessurserM8.java   View Source Code Vote up 3 votes
/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    RequestDispatcher rd = request.getRequestDispatcher("JSP/RessurserM8.jsp");
        rd.include(request, response);    
}
 
Example 19
Project: the-vigilantes   File: RessurserM11.java   View Source Code Vote up 3 votes
/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    RequestDispatcher rd = request.getRequestDispatcher("JSP/RessurserM11.jsp");
        rd.include(request, response);    
}
 
Example 20
Project: the-vigilantes   File: RessurserM4.java   View Source Code Vote up 3 votes
/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    RequestDispatcher rd = request.getRequestDispatcher("JSP/RessurserM4.jsp");
        rd.include(request, response);    
}