@Override public void doTag() throws JspException, IOException { // TODO Auto-generated method stub PageContext pageContext=(PageContext) this.getJspContext(); HttpServletRequest request=(HttpServletRequest) pageContext.getRequest(); HttpServletResponse response=(HttpServletResponse) pageContext.getResponse(); //1���õ�������referer String referer=request.getHeader("referer"); //2���ж������ߵ�ҳ���Dz���Ҫ����������վ if(referer==null || !referer.startsWith(site)){//�ǵ����� if(page.startsWith(request.getContextPath())){ response.sendRedirect(page); }else if(page.startsWith("/")){ response.sendRedirect(request.getContextPath()+page); }else{ response.sendRedirect(request.getContextPath()+"/"+page); } //����ǵ����ߣ�jsp���µ�ҳ��Ͳ��������߲鿴 throw new SkipPageException(); } }
/** * Forwards to another relative page. User browser will still be pointing to the same URL as before. */ protected void forward(String uri) throws JspException, IOException, SkipPageException { PageContext context = (PageContext)this.getJspContext(); try { context.forward(uri); } catch (ServletException e) { throw new JspException("Error in "+getClass().getSimpleName()+" while forwarding to "+uri,e); } throw new SkipPageException(); }
protected GameState assertGame() throws IOException, SkipPageException { GameState game = getGame(); if (game==null) { HttpServletResponse response = getResponse(); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, ERROR_MISSING_GAME_STATE); throw new SkipPageException(); } else { return game; } }
protected RoboToyServerController assertController() throws IOException, SkipPageException { RoboToyServerController controller = getController(); if (controller==null) { HttpServletResponse response = getResponse(); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, ERROR_MISSING_CONTROLLER); throw new SkipPageException(); } else { return controller; } }
private void checkForAdminUser(String userName) throws SkipPageException, IOException { if (userName==null) return; String adminUserName = assertController().getAdminUserName(); if (adminUserName==null) return; if (adminUserName.equalsIgnoreCase(userName)) { // Should redirect admin to special page getResponse().sendRedirect("options.jsp"); throw new SkipPageException(); } }
/** * This tag throw a SkipPageException to the response. What this does it to print * everything on the page till that point when the tag is invoked BUT do not print * anything after the tag. */ @Override public void doTag() throws JspException, IOException { getJspContext().getOut().print("Message from within SkipPageExceptionThrowTag doTag() method.<br>"); getJspContext().getOut().print("Throwing a JSP SkipPageException.....<br>"); try{ int i = 10/0; //will throw Arithmatic Exception }catch(Exception exception){ System.out.println(this.getClass().getName() + " : Got exception in doTag() method: " + exception.getMessage()); //SkipPageException extends JspException throw new SkipPageException(); } }
@Override public void doTag() throws JspException, IOException { try { String croppedDescription = description; if (description != null && description.length() > 50) croppedDescription = description.substring(0, 50) + " ..."; getJspContext().getOut().write(croppedDescription); } catch (Exception e) { e.printStackTrace(); // stop page from loading further by throwing SkipPageException throw new SkipPageException("Exception in cropping " + " with description " + description); } }
/** * Redirects to another page, maybe in another server. User browser will point to the new URL. */ protected void redirect(String url) throws JspException, IOException, SkipPageException { getResponse().sendRedirect(url); throw new SkipPageException(); }
@Override public void doTag() throws JspException, IOException { // TODO Auto-generated method stub throw new SkipPageException(); }