本文整理匯總了Java中javax.servlet.RequestDispatcher.forward方法的典型用法代碼示例。如果您正苦於以下問題:Java RequestDispatcher.forward方法的具體用法?Java RequestDispatcher.forward怎麽用?Java RequestDispatcher.forward使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.servlet.RequestDispatcher
的用法示例。
在下文中一共展示了RequestDispatcher.forward方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: doGet
import javax.servlet.RequestDispatcher; //導入方法依賴的package包/類
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String destino;
request.setCharacterEncoding("UTF-8");
HttpSession sessao = request.getSession();
if (sessao.getAttribute("usuario") != null) {
request.setAttribute("usuario", sessao.getAttribute("usuario"));
// Remove o atributo da sessao para usuario nao ficar preso na tela de resultados
destino = "alterarUsuario.jsp";
} else {
destino = "alterarUsuario.jsp";
}
RequestDispatcher dispatcher = request.getRequestDispatcher(destino);
dispatcher.forward(request, response);
}
示例2: doGet
import javax.servlet.RequestDispatcher; //導入方法依賴的package包/類
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String destino;
HttpSession sessao = request.getSession();
if (sessao.getAttribute("cliente") != null) {
request.setAttribute("cliente", sessao.getAttribute("cliente"));
// Remove o atributo da sessao para usuario nao ficar preso na tela de resultados
sessao.removeAttribute("cliente");
destino = "/clientes";
} else {
destino = "cadastroCliente.jsp";
}
RequestDispatcher dispatcher = request.getRequestDispatcher(destino);
dispatcher.forward(request, response);
}
示例3: logar
import javax.servlet.RequestDispatcher; //導入方法依賴的package包/類
private void logar(HttpServletRequest request, HttpServletResponse response) throws Exception {
String email = request.getParameter("email");
String senha = request.getParameter("senha");
UsuarioBO bo = new UsuarioBO();
Usuario usuario = bo.logar(email, senha);
if (usuario != null){
request.setAttribute("usuario", usuario);
request.getSession().setAttribute("usuario", usuario);
response.sendRedirect("./FeedControle?operacao=Atualizar");
} else {
request.setAttribute("mensagem", "Usuário ou senha inválidos");
RequestDispatcher rd = request.getRequestDispatcher("index.jsp");
rd.forward(request, response);
}
}
示例4: doGet
import javax.servlet.RequestDispatcher; //導入方法依賴的package包/類
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
HttpSession sessao = request.getSession();
ArrayList<Cliente> Lista = new ArrayList();
ServicoCliente sc = new ServicoCliente();
String codigoempresa = (String) sessao.getAttribute("Empresa");
try {
Lista = (ArrayList<Cliente>) sc.procurarCliente("", Integer.parseInt(codigoempresa));
} catch (Exception e) {
}
sessao.setAttribute("ListaClientes", Lista);
RequestDispatcher dispatcher
= request.getRequestDispatcher("/consultarCliente.jsp");
dispatcher.forward(request, response);
}
示例5: processRequest
import javax.servlet.RequestDispatcher; //導入方法依賴的package包/類
/**
* 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");
HttpSession session = request.getSession(true);
String bruker = (String)session.getAttribute("bruker");
String Foreleser = "Foreleser";
try (PrintWriter out = response.getWriter()) {
if(bruker.equals(Foreleser)) {
RequestDispatcher rd = request.getRequestDispatcher("JSP/AddUser.jsp");
rd.forward(request, response);
}
else
out.println("Feil bruker, du er logget inn som " + bruker);
}
}
示例6: doGet
import javax.servlet.RequestDispatcher; //導入方法依賴的package包/類
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
List<ClientVersion> clientVersionList;
try {
clientVersionList =
new ClientVersionDao(Utility.getDBConnection(this.getServletContext())).getClientVersionList();
if (log.isDebugEnabled())
log.debug("out->: clientVersionList" + clientVersionList);
request.setAttribute("clientVersionList", clientVersionList);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
throw new KiteSQLException(e.getLocalizedMessage());
}
// get UI
if (log.isDebugEnabled())
log.debug("Displaying: client_version.vm");
RequestDispatcher requestDispatcher = request.getRequestDispatcher("client_version.vm");
requestDispatcher.forward(request, response);
}
示例7: editar
import javax.servlet.RequestDispatcher; //導入方法依賴的package包/類
private void editar(HttpServletRequest request, HttpServletResponse response) throws Exception{
try {
Integer id = Integer.parseInt(request.getParameter("id"));
PaisBO paisBO = new PaisBO();
Pais pais = paisBO.selecionar(id);
request.setAttribute("pais", pais);
request.setAttribute("mensagem", "Registro selecionado com sucesso");
} catch (Exception ex){
request.setAttribute("erro", ex.getMessage());
}
RequestDispatcher rd = request.getRequestDispatcher("paginas/paises/cadastro_paises.jsp");
rd.forward(request, response);
}
示例8: processRequest
import javax.servlet.RequestDispatcher; //導入方法依賴的package包/類
/**
* 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/MinSide.jsp");
rd.forward(request, response);
}
}
示例9: forwardToErrorPage
import javax.servlet.RequestDispatcher; //導入方法依賴的package包/類
/**
* Called to forward to the error page
*
* @param request Request we are processing
* @param response Response we are creating
* @param config Login configuration describing how authentication
* should be performed
*/
protected void forwardToErrorPage(Request request, Response response, LoginConfig config) {
RequestDispatcher disp =
context.getServletContext().getRequestDispatcher
(config.getErrorPage());
try {
disp.forward(request.getRequest(), response.getResponse());
} catch (Throwable t) {
log.warn("Unexpected error forwarding to error page", t);
}
}
示例10: doGet
import javax.servlet.RequestDispatcher; //導入方法依賴的package包/類
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
HttpSession session=request.getSession();
RequestDispatcher rs;
try{
int patientId = (int)session.getAttribute("UserID");
if(patientId>0)
{
DatabaseHelper databaseHelper = new DatabaseHelper();
Patient patient = databaseHelper.getPatient(patientId);
ArrayList<ArrayList<Appointment>> appointments = databaseHelper.getAppointments(patientId, "patientId");
if(patient!=null && appointments!=null)
{
rs = request.getRequestDispatcher("bookAppointment.jsp");
request.setAttribute("patient", patient);
request.setAttribute("appointments", appointments);
rs.forward(request, response);
}else
{
//redirect to login
redirectToLogin(request,response);
}
}else
{
//redirect to login
redirectToLogin(request,response);
}
}catch(Exception e){
e.printStackTrace();
//redirect to login
redirectToLogin(request,response);
}
}
示例11: doPost
import javax.servlet.RequestDispatcher; //導入方法依賴的package包/類
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
HttpSession session = request.getSession();
String email = request.getParameter("email");
String password = request.getParameter("password");
Utilisateur user = utilisateurService.connexion(email, password);
if(user != null) {
session.setAttribute("user", user);
response.sendRedirect(response.encodeRedirectURL("./admin/home"));
} else {
request.setAttribute("erreur", "Email ou mot de passe incorect");
RequestDispatcher dispatcher = request.getRequestDispatcher("/WEB-INF/views/login.jsp");
dispatcher.forward(request, response);
}
}
示例12: handleHome
import javax.servlet.RequestDispatcher; //導入方法依賴的package包/類
private void handleHome(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
RequestDispatcher requestDispatcher = request
.getRequestDispatcher("bankhomepage.jsp");
requestDispatcher.forward(request, response);
}
示例13: doGet
import javax.servlet.RequestDispatcher; //導入方法依賴的package包/類
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
HttpSession sessao = request.getSession(false);
if (sessao != null && sessao.getAttribute("usuario") != null) {
response.sendRedirect(request.getContextPath() + "/inicio");
return;
}
RequestDispatcher dispatcher = request.getRequestDispatcher("WEB-INF/jsp/login.jsp");
dispatcher.forward(request, response);
}
示例14: doGet
import javax.servlet.RequestDispatcher; //導入方法依賴的package包/類
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
RequestDispatcher dispatcher
= request.getRequestDispatcher("/cadastroProduto.jsp");
dispatcher.forward(request, response);
}
示例15: doGet
import javax.servlet.RequestDispatcher; //導入方法依賴的package包/類
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
RequestDispatcher rd = req.getRequestDispatcher(dispatchPath);
if (rd == null) {
resp.setContentType("text/plain");
resp.setCharacterEncoding("UTF-8");
resp.getWriter().print(NULL);
} else {
rd.forward(req, resp);
}
}