zoukankan      html  css  js  c++  java
  • JSP URI/URL

     

    JSP URI/URL FAQ: How do I get a URI or URL from a JSP (the request URI or request URL)?

    I was just working with a JSP, and trying to remember how to get information that can be very helpful inside of a JSP, specifically how to determine the Context, URI, and URL from within a JSP.

    To that end, here's the Java source code for a JSP I wrote that will display the Context, URI, and URL for this JSP when it is accessed from a browser:

    <h2>JSP URI, URL, Context</h2>
    
    Request Context Path: <%= request.getContextPath() %>
    Request URI:          <%= request.getRequestURI() %>
    Request URL:          <%= request.getRequestURL() %>
    

      

    When I save this in a file named uriTest.jsp, place it in a context named test that is already running on a Tomcat server on my local computer, and then hit the URL for this JSP (http://localhost:8080/test/uriTest.jsp), I see the following output:

    JSP URI, URL, Context
    
    Request Context Path: /test
    Request URI:          /test/uriTest.jsp
    Request URL:          http://localhost:8080/test/uriTest.jsp
    

    Information like this can be very helpful when doing a variety of things inside a JSP. For instance, in looking at the blog here at devdaily.com/blog, I want to add some social bookmark links here, and when doing that, I can use the =request.getRequestURI() or request.getRequestURL()= methods to get the URL information that I need to send to Digg, StumbleUpon, and others.

    While I mentioned that I ran this test from within Tomcat, you'll use these same Java/JSP methods from within any servlet container, including GlassfishJBoss, WebLogic, or WebSphere.

  • 相关阅读:
    数据导入
    数据库导入导出命令
    题库
    struts2的配置文件简洁
    修改oralce11g 字符集为ZHS16GBK
    Linux上安装JDK+Tomcat
    Android中adb的使用
    【转】Android获取IP的方法,并可以判断手机是否联网
    Android中R.java没有自动生成问题
    Android中SQLiteOpenHelper的理解
  • 原文地址:https://www.cnblogs.com/hephec/p/4586790.html
Copyright © 2011-2022 走看看