當前位置: 首頁>>代碼示例>>Java>>正文


Java HttpServletResponse.sendRedirect方法代碼示例

本文整理匯總了Java中javax.servlet.http.HttpServletResponse.sendRedirect方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpServletResponse.sendRedirect方法的具體用法?Java HttpServletResponse.sendRedirect怎麽用?Java HttpServletResponse.sendRedirect使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.servlet.http.HttpServletResponse的用法示例。


在下文中一共展示了HttpServletResponse.sendRedirect方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: forwardToLogin

import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
private boolean forwardToLogin(HttpServletRequest request,
                               HttpServletResponse response) throws ServletException, IOException {
    String url = "http://" + request.getServerName() + ":"
            + request.getServerPort() + request.getContextPath()
            + "/login.jsp";
    response.sendRedirect(url);
    return false;
}
 
開發者ID:tomoncle,項目名稱:JavaStudy,代碼行數:9,代碼來源:AuthInterceptorAdapter.java

示例2: doFilter

import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
    HttpServletRequest hsrq = (HttpServletRequest) request;
    HttpServletResponse hsrp = (HttpServletResponse) response;
    String clientType = hsrq.getParameter("clientType");
    if ("WORD".equals(clientType)) {
        chain.doFilter(request, response);
    } else {
        SessionUser person = null;
        String reqPage = hsrq.getServletPath();
        if (!reqPage.trim().equals("/login.do") && !reqPage.trim().equals("/logout.do")
                ) {
            person = (SessionUser) hsrq.getSession().getAttribute(SysConstants.SESSION_USER_KEY);
            if (person == null) {
                hsrp.sendRedirect("login.do");
                return;
            }
        }
        chain.doFilter(request, response);
    }

}
 
開發者ID:JiaXiaohei,項目名稱:ssm-web,代碼行數:22,代碼來源:CheckSessionOutFilter.java

示例3: handle

import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
@Override
public void handle(HttpServletRequest httpServletRequest,
                   HttpServletResponse httpServletResponse,
                   AccessDeniedException e) throws IOException {

    Authentication auth = SecurityContextHolder.getContext().getAuthentication();

    // Log access attempts
    if (auth != null) {
        logger.info("User '" + auth.getName() + "' attempted to access the protected URL: "
                + httpServletRequest.getRequestURI());
    }

    // Direct user to access denied page
    httpServletResponse.sendRedirect(httpServletRequest.getContextPath() + "/403");
}
 
開發者ID:ericywl,項目名稱:InfoSys-1D,代碼行數:17,代碼來源:ProfChoperAccessDeniedHandler.java

示例4: doGet

import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
      HttpSession sessao = request.getSession();  
      ArrayList<Fornecedor> Lista = new ArrayList();
      ServicoFornecedor sf = new ServicoFornecedor();
      String codigoempresa = (String) sessao.getAttribute("Empresa");
      
      try {
        Lista = (ArrayList<Fornecedor>) sf.listarFornecedor("", Integer.parseInt(codigoempresa));
    } catch (Exception e) {
    }
    
      sessao.setAttribute("ListaFornecedoresProd", Lista);
      
      RequestDispatcher dispatcher
 = request.getRequestDispatcher("/cadastroProduto.jsp");
dispatcher.forward(request, response);
response.sendRedirect(request.getContextPath() + "/cadastroProduto.jsp"); 
}
 
開發者ID:Dinossaura,項目名稱:LojaDeInstrumentosMusicais,代碼行數:21,代碼來源:ConsultaFornecedorProdServlet.java

示例5: logout

import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
/**
 * 用戶登出係統
 */
@RequestMapping("/logout")
public void logout(HttpServletRequest request, HttpServletResponse response) throws IOException
{
	try
	{
		MyCookie cookie = new MyCookie(request, response);
		String cookieTicket = String.valueOf(cookie.getValue(SessionListener.DS_SSO_TICKET));
		service.saveLogLogout(String.valueOf(cookieTicket), false, false);
		if(!cookieTicket.equals("null") && cookieTicket.length() > 0)
		{
			removeLoginInfo(request, response);// 試著刪除
		}
	}
	catch(Exception e)
	{
		log.error(e.getMessage());
	}
	MyRequest req = new MyRequest(request);
	String serviceURL = java.net.URLEncoder.encode(req.getString("service", request.getContextPath() + "/ticket.jsp"), "UTF-8");
	response.sendRedirect(request.getContextPath() + "/login?service=" + String.valueOf(serviceURL));
	return;
}
 
開發者ID:skeychen,項目名稱:dswork,代碼行數:26,代碼來源:AuthController.java

示例6: doGet

import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
/**
 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
 */
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	CreateSurveySessionManager session = new CreateSurveySessionManager(request);
	if (securityService.isLoggedIn()) {
		if (session.hasSurveyModel()) {
			request.getRequestDispatcher("WEB-INF/createsurvey/createsurvey.jsp").forward(request, response);
			session.clearErrorMessages();
		} else {
			response.sendRedirect("lecturer");
			session.clearErrorMessages();
		}
	} else {
		session.setErrorMessage(ErrorMessage.NOT_LOGGED_IN);
		response.sendRedirect("index");
	}
}
 
開發者ID:erikns,項目名稱:webpoll,代碼行數:19,代碼來源:SurveyBuilderServlet.java

示例7: handlePost

import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
public void handlePost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	String path = getPath(request);
	
	System.out.println("GUIPOSTPATH "+path);
	if (path.equals("login")) {
		String email = request.getParameter("email");
		String pwd = request.getParameter("pword");
		System.out.println("LoggingIn "+email);
		IResult r = model.authenticate(email, pwd);
		ITicket t = (ITicket)r.getResultObject();
		if (t != null) {
			String rtoken = newUUID();
			
			credentialCache.putTicket(rtoken, t);
			response.sendRedirect("/gui/menu/"+rtoken);
		}
	}

			
}
 
開發者ID:topicquests,項目名稱:backside-servlet-ks,代碼行數:21,代碼來源:GUIHandler.java

示例8: doLogin

import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
/**
 * do login
 * @param user userInfo
 * @param request requestInfo
 * @param response responseInfo
 * @param map data
 * @return login result
 * @throws IOException
 */
@RequestMapping(value="login",method = RequestMethod.POST)
public String doLogin(User user, HttpServletRequest request, HttpServletResponse response,ModelMap map) throws IOException{
    if(!StringUtils.isEmpty(user.getName())){
        request.getSession().setAttribute(Constant.SESSION_USER_KEY,user);

        //login success, redirect to home controller, change the url also. if return viewName,can't change url.
        response.sendRedirect("/home");
        return null;
    }else{
        map.put("welcomeMsg",this.msg);
        return "login"; //login failure, return login page
    }
}
 
開發者ID:hsj-xiaokang,項目名稱:springboot-shiro-cas-mybatis,代碼行數:23,代碼來源:CommonController.java

示例9: doUndo

import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
@Override
protected void doUndo(HttpServletRequest request, HttpServletResponse response)
		throws ServletException, IOException, SQLException {
	// TODO Auto-generated method stub
	String id = request.getParameter("Id");
       if (id != null && !id.trim().isEmpty()) {
       	int ID = Integer.parseInt(id);
       	int amount = saDAO.getAmount(COMPONENT, ID) - FIXEDVALUE;
       	saDAO.updateIncidentToPerson(id, amount, COMPONENT);
       }
       
       response.sendRedirect(LINKNAME);
}
 
開發者ID:qianyilun,項目名稱:Queue-Manager-Cloud-Dispatcher,代碼行數:14,代碼來源:PersistenceWithSA.java

示例10: doGet

import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
protected void doGet( HttpServletRequest req, HttpServletResponse resp )
		throws ServletException, IOException {
	String oper=req.getParameter( "oper" );
	if( log.isDebugEnabled() ) {
		log.debug( "oper=" + oper );
	}
	
	DecisionEntitlementHandler handler=getHandler( req );
	req.setAttribute( "handler", handler );
	
	if( "loadEntitlements".equals( oper ) ) {
		WebUtil.forward( req, resp, "/ralasafe/privilege/decisionEntitlementTable.jsp" );
		return;
	} else if( "getEntitlement".equals( oper ) ) {
		int index=WebUtil.getIntParameter( req, "index", -23 );
		if( index>=0 ) {
			DecisionEntitlement entitlement=(DecisionEntitlement) handler.getDecisionEntitlements().get( index );
			req.setAttribute( "entitlement", entitlement );				
		}
		
		WebUtil.forward( req, resp, "/ralasafe/privilege/editDecisionEntitlement.jsp" );
		return;
	} else if( "return".equals( oper ) ) {
		String gotoUrl="./nonRolePrivilegeMng.rls";
		if( handler.getPrivilege().getType()==0 ) {
			gotoUrl="./privilegeMng.rls";
		} 
		
		String key=getHandlerAttributeKey( req );
		req.getSession().removeAttribute( key );
		
		resp.sendRedirect( gotoUrl );
		return;
	} else {
		WebUtil.forward( req, resp, "/ralasafe/privilege/decisionEntitlement.jsp" );
		return;
	}
}
 
開發者ID:yswang0927,項目名稱:ralasafe,代碼行數:39,代碼來源:DecisionEntitlementAction.java

示例11: doGet

import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    HttpSession session = request.getSession();

    int logID = Integer.parseInt(request.getParameter("logID"));
    SchoolAccounts account = (SchoolAccounts) session.getAttribute("schoolAccount");
    SchoolLoginLogs loginLog = SchoolAccountDataAccessObject.getLoginLogByID(logID);

    if (loginLog != null) {
        List<SchoolActivityLogs> activityLogs = loginLog.getActivityLog();
        session.setAttribute("schoolActivityLogs", activityLogs);
    }
    response.sendRedirect("admin/admin-school-logs.jsp");
}
 
開發者ID:faizan-ali,項目名稱:full-javaee-app,代碼行數:14,代碼來源:AdministratorSchoolSessionStatisticsServlet.java

示例12: render

import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
@Override
public void render(HttpServletRequest request, HttpServletResponse response) throws RenderException {
    getContxtPath(request);
    String finalUrl = buildFinalUrl(request);
    try {
        response.sendRedirect(finalUrl);
    } catch (IOException e) {
        throw new RenderException(e.getMessage(), e);
    }
}
 
開發者ID:Xlongshu,項目名稱:EasyController,代碼行數:11,代碼來源:RedirectView.java

示例13: doHeartbeat

import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
@Override
public void doHeartbeat(HttpServletRequest request, HttpServletResponse response) {
  try {
    response.sendRedirect("ctrip_sso_heartbeat.html");
  } catch (IOException e) {
  }
}
 
開發者ID:dewey-its,項目名稱:apollo-custom,代碼行數:8,代碼來源:CtripSsoHeartbeatHandler.java

示例14: doPost

import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	String party = request.getParameter("pname");
	String event = request.getParameter("ename");
	String page="";
	String sql="insert into event values('"+party+"', '"+event+"')";
	
	if(party.equals("") || event.equals(""))
	{
		page="Add_UpcommingEvent.jsp?msg=failure";
	}
	else
	{
		try
		{
			Model m =new Model();
			m.setParty(party);
			m.setEvent(event);
			
			int i = Dao.register(m,sql);
			if(i!=0)
			{
				page="Add_UpcommingEvent.jsp?msg=success";
			}
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
		response.sendRedirect(page);
	}	
}
 
開發者ID:nishittated,項目名稱:OnlineElectionVotingSystem,代碼行數:32,代碼來源:AddEvent.java

示例15: login

import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
/**
 * 處理從QQ到12345網站的單點登錄
 *
 * @param response
 * @return
 * @throws Exception
 */
@RequestMapping("/qqLogin")
public void login(HttpServletResponse response) throws Exception {
    try {
        String redirect_url = "https://graph.qq.com/oauth2.0/authorize?" +
                "client_id=" + SSOCommon.qqAppKey +
                "&redirect_uri=" + SSOCommon.qqRedirectUri +
                "&response_type=code" +
                "&state=" + RandomStringUtils.randomAlphanumeric(10) +      //設置為簡單的隨機數
                "&scope=get_user_info";
        response.sendRedirect(redirect_url);
    } catch (Exception e) {
        logger.error("調用QQ接口異常!", e);
    }
}
 
開發者ID:Zephery,項目名稱:newblog,代碼行數:22,代碼來源:IndexController.java


注:本文中的javax.servlet.http.HttpServletResponse.sendRedirect方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。