[英]How can I detect portion of URL and output value if condition matches?
I need to create a special condition if the page URL in the browser address bar ends in "search". 如果浏览器地址栏中的页面URL以“搜索”结尾,则需要创建特殊条件。 In my .jpsf file, I have this code so far:
到目前为止,在我的.jpsf文件中,我有以下代码:
<c:choose>
<c:when test="${SOMETHINGHERE eq 'Search'}">
<c:out value="Search" />
</c:when>
<c:otherwise>
<c:out value="${topCat}" />|<c:out value="${subCatA}" />|<c:out value="${subCatB}" />|<c:out value="${subCatC}" />
</c:otherwise>
</c:choose>
What can I put in the SOMETHINGHERE
section to detect if the URL contains the word search? 我可以在
SOMETHINGHERE
部分中放置什么来检测URL是否包含单词search? Browsing the posts here and searching on Google has not led me to any answers that work so far. 浏览此处的帖子并在Google上进行搜索至今还没有找到任何可行的答案。
I also tried adding <% String currentPDP = request.getParameter("search")%>
but it returned a 500 error, probably because _Search is not set up properly as a parameter (it's hard coded at the end of a URL) and the code is not properly formatted. 我还尝试添加
<% String currentPDP = request.getParameter("search")%>
但它返回了500错误,可能是因为_Search未正确设置为参数(在URL的末尾硬编码)和代码格式不正确。
I am new to JSP and have to learn on the job, so I appreciate your patience and any help you can offer. 我是JSP的新手,必须在工作中学习,因此,感谢您的耐心和能提供的任何帮助。 Thank you kindly.
非常感谢你。
First you'd want to import the Functions tag with: 首先,您要使用以下命令导入Functions标签:
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
Then, you can use: 然后,您可以使用:
${fn:contains(pageContext.request.requestURI, 'Search')}
or, if you don't care about the case 或者,如果您不在乎情况
${fn:containsIgnoreCase(pageContext.request.requestURI, 'Search')}
That will allow you to search through the URI for the term Search
. 这样,您就可以在URI中
Search
术语Search
。
If the full url to the running script was http://www.example.com/site/search.jsp
, then responseURL
should return /site/search.jsp
. 如果正在运行的脚本的完整URL为
http://www.example.com/site/search.jsp
,则responseURL
应该返回/site/search.jsp
。 The above examples would return true in the second case because 'Search' is in the URI string (the first would fail due to capitalization). 上面的示例在第二种情况下将返回true,因为URI字符串中包含“ Search”(第一个由于大写而失败)。
It does not include query parameters, which would involve a different check. 它不包括查询参数,查询参数将涉及不同的检查。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.