java如何访问jsp中键入的当前页面url?
我使用。htaccess用于url重写的文件。使能。htaccess文件我将urlwritefilter-4.0.3放入。jarWEB-INF\lib\和WEB内部的文件。xml我添加了以下代码
<filter>
<filter-name>UrlRewriteFilter</filter-name>
<filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
默认为false。使用mod_重写样式配置文件(如果这是真的且未指定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>`
我的。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]
我有一个用户。jsp文件。我使用正则表达式进行url映射,这样无论我在url中键入什么,它都会打开用户。jsp文件。
我想访问用户内部键入的实际url。jsp文件。
假设我键入http://localhost:8080/project/abhiramgiri
。我曾经
<%
String getURL=request.getRequestURI();
out.print(getURL);
%>
它将文件的路径显示为http://localhost:8080/project/user.jsp
实际上我需要http://localhost:8080/project/abhiramgiri
。
它不显示实际键入的url。它检索原始路径。
请帮我解决这个问题
# 1 楼答案
显示web浏览器的URL是什么?根据您的应用程序,您可以使用JavaScript通过文档获取URL。网址(见get-current-url-with-javascript) 你必须注意安全