Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/397.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何检查字符串的JSP请求URL_Java_Jsp - Fatal编程技术网

Java 如何检查字符串的JSP请求URL

Java 如何检查字符串的JSP请求URL,java,jsp,Java,Jsp,我有以下processor.jsp文件: <% response.sendRedirect("http://buzz.example.com"); %> 然而,这不起作用。关于我应该使用什么而不是请求,或者如果我做了其他错误的事情,你有什么想法吗?总是尽量避免使用Scriplet,因为Scriplet更容易使用,也不容易出错 使用JSTL的示例代码,相当于Java开关大小写 <%@ taglib prefix="c" uri="http://java.sun.com/

我有以下
processor.jsp
文件:

<%
    response.sendRedirect("http://buzz.example.com");
%>
然而,这不起作用。关于我应该使用什么而不是
请求
,或者如果我做了其他错误的事情,你有什么想法吗?

总是尽量避免使用Scriplet,因为Scriplet更容易使用,也不容易出错

使用JSTL
的示例代码,相当于Java
开关
大小写

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
...

<c:set var="defaultURL" value="xyz"/>

<c:choose>
    <c:when test="${fn:containsIgnoreCase(request.getRequestURI(), 'fizz')}">
        <c:redirect url="http://fizz.example.com" />
    </c:when>
    <c:when test="${fn:containsIgnoreCase(request.getRequestURI(), 'buzz')}">
        <c:redirect url="http://buzz.example.com" />
    </c:when>
    <c:otherwise>
        <c:redirect url="http://${defaultURL}.example.com" />
    </c:otherwise>
</c:choose>

...

首先阅读更多关于和的信息:不要使用JSP,使用Servlet过滤器。谢谢@LuiggiMendoza(+1)-但是我必须在这里使用JSP。我会留出这么长的后台故事,但它绝对必须通过JSP完成,相信我。你的代码不起作用的原因是你使用了一个不存在的函数
request.getURL()
,而不是
request.getRequestURL()
,对不起,我不能信任使用scriptlet解决他/她的问题的人的设计。
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
...

<c:set var="defaultURL" value="xyz"/>

<c:choose>
    <c:when test="${fn:containsIgnoreCase(request.getRequestURI(), 'fizz')}">
        <c:redirect url="http://fizz.example.com" />
    </c:when>
    <c:when test="${fn:containsIgnoreCase(request.getRequestURI(), 'buzz')}">
        <c:redirect url="http://buzz.example.com" />
    </c:when>
    <c:otherwise>
        <c:redirect url="http://${defaultURL}.example.com" />
    </c:otherwise>
</c:choose>