简体   繁体   English

如何访问在jsp中键入的当前页面URL?

[英]How to access the current page url typed in jsp?

I use .htaccess file for url rewritting.To enable .htaccess file I put the urlrewritefilter-4.0.3.jar file inside WEB-INF\\lib\\ and inside web.xml I have added the following code. 我使用.htaccess文件进行url重写。为了启用.htaccess文件,我将urlrewritefilter-4.0.3.jar文件放在WEB-INF \\ lib \\中,在web.xml中我添加了以下代码。

   <filter>
      <filter-name>UrlRewriteFilter</filter-name>
          <filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>

defaults to false. 默认为false。 use mod_rewrite style configuration file (if this is true and confPath is not specified confPath will be set to /WEB-INF/.htaccess) 使用mod_rewrite样式的配置文件(如果为true并且未指定confPath,则confPath将设置为/WEB-INF/.htaccess)

   <init-param>
       <param-name>modRewriteConf</param-name>
       <param-value>true</param-value>
   </init-param>
   </filter>
   <filter-mapping>
    <filter-name>UrlRewriteFilter</filter-name>
    <url-pattern>/*</url-pattern>
    <dispatcher>REQUEST</dispatcher>
    <dispatcher>FORWARD</dispatcher>
   </filter-mapping>`

My .htacces file code is 我的.htacces文件代码是

    RewriteRule ^/()$ index.jsp [NC,L]
    RewriteRule ^/login/?$ login.jsp [NC,L] #Handle requests for "login"
    RewriteRule ^/logout/?$ login.jsp [NC,L] #Handle requests for "login"
    RewriteRule ^/contact_us/?$ contact.jsp [NC,L] #Handle requests for "contactus"
    RewriteRule ^([/A-Za-z0-9_]+)$ user.jsp [NC,L]
    RewriteRule ^([/A-Za-z0-9_]+)/$ user.jsp [NC,L]

I have one user.jsp file. 我有一个user.jsp文件。 I used regular expression for url maping so that what ever i type in url it open the user.jsp file. 我使用正则表达式进行url映射,以便我在url中键入的内容都可以打开user.jsp文件。 I want to access the actual url typed inside the user.jsp file. 我想访问在user.jsp文件中键入的实际URL。 Suppose I type http://localhost:8080/project/abhiramgiri . 假设我输入http://localhost:8080/project/abhiramgiri I used 我用了

  <%
       String getURL=request.getRequestURI();
       out.print(getURL);
  %>

It shows the path to the file as http://localhost:8080/project/user.jsp Actually I need http://localhost:8080/project/abhiramgiri . 它显示文件的路径为http://localhost:8080/project/user.jsp实际上,我需要http://localhost:8080/project/abhiramgiri It does not show the actual typed url. 它不显示实际键入的URL。 It retrieve the original path. 它检索原始路径。 Please, Help me for this problem. 请帮我解决这个问题。

What is it the URL that shows the web browser? 显示网络浏览器的URL是什么? depending on your application you could use JavaScript to get the URL using document.URL (see get-current-url-with-javascript ) You must regard security. 根据您的应用程序,您可以使用JavaScript通过document.URL获取URL(请参阅get-current-url-with-javascript )。您必须考虑安全性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM