zoukankan      html  css  js  c++  java
  • JSP_BASEPATH

    Eclipse 新建 jsp页面里自动生成以下代码:

    <%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
    %>

    作用相当生成了以下路径:

    path=WebName ; (当前站点名称)

    转自:http://blog.csdn.net/lutinghuan/article/details/6450174/

    basePath= http  ://  localhost : 8080 /WebName / 

    (http://localhost:8080/WebName/ 这个在IE地址览里最熟悉不过的地址就是这样产生的)

    1.这样的好处在于可以为当前的链接使用绝对路径(同时,也强烈推荐使用绝对路径),如:

    <a href="<%=basePath %>index.jsp">跳回首页</a>

    2.在jsp页面还自动生成了以下代码:

    <base href="<%=basePath %>" />

    它指定了当前页面的默认地址为basePath,所以

    <a href="index.jsp">跳回首页</a>

    即真实的跳转路径为:http://localhost:8080/WebName/index.jsp

    ------------------------------------------------------------------------------

    通过转发访问WEB-INF资源http://www.cnblogs.com/qq3111901846/p/6242096.html

    <%@ page language="java" import="java.util.*" contentType="text/html; charset=utf-8"%>
    
    <% 
      request.setCharacterEncoding("utf-8");
    %>
    
    <%
      String path = request.getContextPath();
      String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
      
         session.setAttribute("loginUser", request.getParameter("username"));
         //通过转发访问WEB-INF资源:WEB-INF为安全目录(位于服务器端,只有服务器级别才能访问,转发就是服务器级别)
         request.getRequestDispatcher("WEB-INF/jsp/goforwed.jsp").forward(request, response);
        // response.sendRedirect("login_failure.jsp");
      
    %>
  • 相关阅读:
    C 扩展库
    访问nginx时验证密码
    关于redis闪退的案例
    查看进程的准确启动时间
    Ansible随笔8
    Ansible-随笔-7
    运维基本工作
    随笔-ansible-6
    随笔-ansible-5
    随笔-ansible-4
  • 原文地址:https://www.cnblogs.com/charles999/p/6841086.html
Copyright © 2011-2022 走看看