Results 1 to 5 of 5
  1. #1
    jeremy.wilson is offline Member
    Join Date
    Jul 2009
    Location
    Seattle, WA
    Posts
    23
    Rep Power
    0

    Default Trouble with a Redirect Script - Looking for Assistance

    The following code is only working for me half of the time. That half that works is that which gets called only when the user comes from another page on the same domain, with some additional parameters coming in tow.

    The other half is the behavior when the user tries to access this page without first having come from a specific referring URL. This is where my script is failing and I don't seem to understand why.

    In the event that they hit this page without first having come directly from somedomain.com, I want them to redirect to another URL, same as when I have already successfully redirected them URL.

    The part which is not working as expected for me, I've highlighted it in red.

    Java Code:
    <%@ page import="java.lang.*" %>
    <%@ page language="java" import="java.util.*"%>
    
    <%     //get parameters from the URL
    String referer = request.getHeader("referer");
          if (referer == null) {
                referer = "";
          }
    String pid = request.getParameter("pid");
          if (pid == null) {
                pid = "";
          }
    String source = request.getParameter("source");
          if (source == null) {
                source = "";
          }
    String sku = request.getParameter("sku");
          if (sku == null) {
                sku = "";
          } else {
    
                //get parent node
                String sourceParentNode = sku.substring(0,1);
                out.println("sourceParentNode: " + sourceParentNode + "<br />");
    
                // now let's start building the redirect URL
                // we need to determine which domain the request came from
                // and whether they are bringing the three expected parameters with them
    
                String redirectURL = "";
                String redirectFinalURL = "";
                Boolean redirectCookies = false;
    
                [COLOR="Green"]  if (referer.contains("somedomain.com")) {                        // user hits this web page only from if somedomain.com is the referer, then if all additional parameters match, is sent to special promotional page.
                    if ((sourceParentNode.equals("6")) || (sourceParentNode.equals("7"))) {
                            if (pid.equals("74628")) {
                                  if ((source.equals("DC")) || (source.equals("LM")) || (source.equals("CS")) || (source.equals("FB"))) {
    
                                        redirectURL = "somedomain.com/offer.html";
    
                                  }
                            } 
                      }
                }[/COLOR] [COLOR="Red"]else {                                                    // default condition, send to home page
                      redirectURL = "somedomain.com/goaway";
                }[/COLOR]
    
          redirectFinalURL = redirectURL;
          response.sendRedirect(redirectFinalURL);
    
          }
    %>

  2. #2
    jeremy.wilson is offline Member
    Join Date
    Jul 2009
    Location
    Seattle, WA
    Posts
    23
    Rep Power
    0

    Default

    Is there a simple way I can detect the referer value using JSTL, then redirect based on a successful detection of a specific URL? Basically, can anyone show me how I might use JSTL to duplicate the above outdated script example?

  3. #3
    jeremy.wilson is offline Member
    Join Date
    Jul 2009
    Location
    Seattle, WA
    Posts
    23
    Rep Power
    0

    Default

    And I did make an attempt but I'm having difficulty figuring out how to use JSTL to pull down the header information and do a partial match. Here is my code so far.

    Java Code:
    <%@ page session="false" %>
    <%@ taglib prefix="cms" uri="wwwdotopencmsdotorg/taglib/cms" %> 
    
    <%@ taglib prefix="c" uri="javadotsundotcom/jstl/core" %>
    <%@ taglib uri="jakartadotapachedotorg/taglibs/regexp-1.0" prefix="rx" %>
    <%@ taglib uri="jakartadotapachedotorg/taglibs/string-1.1" prefix="str" %>
    
    <!-- serialize the posted variables for parsing the redirection logic -->
    <c:set var="referer"><c:out value="${param.referer}"/></c:set>
    <c:set var="sku"><c:out value="${param.sku}"/></c:set>
    <c:set var="pid"><c:out value="${param.pid}"/></c:set>
    <c:set var="source"><c:out value="${param.source}"/></c:set>
    
    <!-- serialize the hard values for variables for comparison to posted variables -->
    <c:set var="refererValue">somedomain.com</c:set>
    <c:set var="pidValue">1234</c:set>
    <c:set var="skuValue">6</c:set>
    
    <c:set var="sourceValue">
    	<c:if test="${param.source == 'AB'}"><c:set var="sourceType">AB</c:set></c:if>
    	<c:if test="${param.source == 'CD'}"><c:set var="sourceType">CD</c:set></c:if>
    	<c:if test="${param.source == 'EF'}"><c:set var="sourceType">EF</c:set></c:if>
    	<c:if test="${param.source == 'GH'}"><c:set var="sourceType">GH</c:set></c:if>
    	<c:out value="${param.sourceType}"/>
    </c:set>
    
    <c:choose>
    	<c:when test="${referer == refererValue}">
    		<c:choose>
    			<c:when test="${pid == pidValue}">
            			<c:choose>
                    			<c:when test="${sku == skuValue}">
    						<c:choose>
    							<c:when test="${source == sourceType}">
    								<%
    								String redirectURL = "/thefirsturl";
    								response.sendRedirect(redirectURL);
    								%>
    
    							</c:when>
    						</c:choose>
    					</c:when>
    				</c:choose>
    			</c:when>
    		</c:choose>
    	</c:when>
    	<c:otherwise>
    		<%
    			String redirectURL = "/someurl";
    			response.sendRedirect(redirectURL);
    		%>
    	</c:otherwise>
    </c:choose>

  4. #4
    jeremy.wilson is offline Member
    Join Date
    Jul 2009
    Location
    Seattle, WA
    Posts
    23
    Rep Power
    0

    Default

    Late coming back to this but the problem(s) I was experiencing above are at least in part due to the lack of HTTP Referrer information coming through from the website we are expecting people to come through first, before coming to ours.

    So my attempts to capture that 'referer' information at perform some kind of a match (<c:when test=${referer == refererValue}"> code block) against the expected value, would of course fail.

    And the last realization I had was that the referring site is not sending the information to us in the form of a querystring parameter, so my param.referer reference above was incorrect. I believe it would make more sense to change that out for the following:
    Last edited by jeremy.wilson; 12-30-2009 at 09:45 PM.

  5. #5
    jeremy.wilson is offline Member
    Join Date
    Jul 2009
    Location
    Seattle, WA
    Posts
    23
    Rep Power
    0

    Question

    Java Code:
    <%@ page session="false" %>
    <%@ taglib prefix="cms" uri="wwwdotopencmsdotorg/taglib/cms" %> 
    
    <%@ taglib prefix="c" uri="javadotsundotcom/jstl/core" %>
    <%@ taglib uri="jakartadotapachedotorg/taglibs/regexp-1.0" prefix="rx" %>
    <%@ taglib uri="jakartadotapachedotorg/taglibs/string-1.1" prefix="str" %>
    
    <!-- serialize the posted variables for parsing the redirection logic -->
    [COLOR="Lime"]<c:set var="referer"><%=request.getHeader("referer")%></c:set>[/COLOR]
    <c:set var="sku"><c:out value="${param.sku}"/></c:set>
    <c:set var="pid"><c:out value="${param.pid}"/></c:set>
    <c:set var="source"><c:out value="${param.source}"/></c:set>
    
    <!-- serialize the hard values for variables for comparison to posted variables -->
    <c:set var="refererValue">somedomain.com</c:set>
    <c:set var="pidValue">1234</c:set>
    <c:set var="skuValue">6</c:set>
    
    <c:set var="sourceValue">
    	<c:if test="${param.source == 'AB'}"><c:set var="sourceType">AB</c:set></c:if>
    	<c:if test="${param.source == 'CD'}"><c:set var="sourceType">CD</c:set></c:if>
    	<c:if test="${param.source == 'EF'}"><c:set var="sourceType">EF</c:set></c:if>
    	<c:if test="${param.source == 'GH'}"><c:set var="sourceType">GH</c:set></c:if>
    	<c:out value="${param.sourceType}"/>
    </c:set>
    
    <c:choose>
    	[COLOR="Red"]<c:when test="${referer == refererValue}">[/COLOR]
    		<c:choose>
    			<c:when test="${pid == pidValue}">
            			<c:choose>
                    			<c:when test="${sku == skuValue}">
    						<c:choose>
    							<c:when test="${source == sourceType}">
    								<%
    								String redirectURL = "/thefirsturl";
    								response.sendRedirect(redirectURL);
    								%>
    
    							</c:when>
    						</c:choose>
    					</c:when>
    				</c:choose>
    			</c:when>
    		</c:choose>
    	</c:when>
    	<c:otherwise>
    		<%
    			String redirectURL = "/someurl";
    			response.sendRedirect(redirectURL);
    		%>
    	</c:otherwise>
    </c:choose>

Similar Threads

  1. Error assistance
    By bobbychiken in forum New To Java
    Replies: 2
    Last Post: 11-21-2009, 10:54 PM
  2. Looking for assistance
    By s_dawg101 in forum New To Java
    Replies: 32
    Last Post: 11-04-2009, 02:49 AM
  3. New to the forum + assistance :)
    By quemadissimo in forum New To Java
    Replies: 4
    Last Post: 10-31-2009, 06:41 AM
  4. In need of some assistance
    By Boer84 in forum New To Java
    Replies: 2
    Last Post: 07-08-2008, 04:14 PM
  5. X-Tremely new to this...Need assistance...
    By Johnny562 in forum New To Java
    Replies: 5
    Last Post: 07-01-2008, 09:17 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •