Question

I have been tasked with applying a new look and feel to an existing JSP site.

However, I am having a problem where my CSS is preventing JSP functionality - which to me seems very weird.

Basically, there is a line of code in the JSP, which redirects the page once a form has been submitted.

String redirectUrl = "Absolute path to next page"
response.sendRedirect(redirectUrl);

For development purposes, I am creating my CSS in the page head - inline. When I do this, the sendRedirect does not work. Viewing the source of the page, I can see the page only part loads, and ends halfway through my CSS. (it doesn't matter what CSS i put, the source of the page always ends in my CSS)

If I move my CSS to external files (which it ultimately will be), the sendRederct works just fine.

The only thing I can think is happening, is JSP can only handle a certain number of lines of code, and my CSS is bloating the page out too much for it to handle. Is that the case?

If not, what else could be causing the problem?

Edit -- HERE IS MY CODE

<!DOCTYPE HTML>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-GB">
<head>
    <%@ page contentType="text/html; charset=utf-8" pageEncoding="utf-8" %>
  <meta charset="utf-8" /><%@include file="/WEB-INF/ss_layout_head_info.jsp"%>

    <%=serverbean.evalResInc("internet_2.0_opening_head_content")%>
    <%-- Instantiate the form validation bean and supply the error message map --%>
    <%@ page import="company.forms.FeedbackFormBean" %>
    <%@ page import="java.util.*" %>
    <%
        java.util.Map errorMap = new java.util.HashMap();;
        errorMap.put(FeedbackFormBean.ERR_FULLNAME_ENTER, serverbean.evalIdcScp("langRef(#active.ssLanguage, \"ww2SpecifyFullName\")"));
        errorMap.put(FeedbackFormBean.ERR_EMAIL_ENTER, serverbean.evalIdcScp("langRef(#active.ssLanguage, \"ww2SpecifyEmailAddress\")"));
        errorMap.put(FeedbackFormBean.ERR_EMAIL_INVALID, serverbean.evalIdcScp("langRef(#active.ssLanguage, \"ww2EmailAddressNotValid\")"));
        errorMap.put(FeedbackFormBean.ERR_COMMENTS_ENTER, serverbean.evalIdcScp("langRef(#active.ssLanguage, \"ww2SpecifyComments\")"));
        errorMap.put(FeedbackFormBean.ERR_POSSIBLE_SPAM, serverbean.evalIdcScp("langRef(#active.ssLanguage, \"ww2PossibleSpamInput\")"));
    %>

    <%String httpAbsoluteCgiPath = serverbean.evalIdcScp("HttpAbsoluteCgiPath");%>
    <%String siteId = serverbean.evalIdcScp("siteId");%>
    <%String nodeId = serverbean.evalIdcScp("nodeId");%>
    <%String fs = serverbean.evalIdcScp("fs");%>

    <jsp:useBean id="form" class="company.forms.FeedbackFormBean" scope="request">
        <jsp:setProperty name="form" property="errorMessages" value='<%= errorMap %>'/>
        <jsp:setProperty name="form" property="siteId" value='<%= siteId %>'/>
    </jsp:useBean>

    <%if ("true".equals(request.getParameter("process"))) { %>
        <jsp:setProperty name="form" property="*" />
        <%if (form.process()) {
            serverbean.putLocal("fullName", form.getFullName());
            serverbean.putLocal("email", form.getEmail());
            serverbean.putLocal("phone", form.getPhone());
            serverbean.putLocal("comments", form.getComments());
            serverbean.putLocal("dUser", "sysadmin");

            serverbean.putLocal("IdcService", "INTERNET_2.0_CHECKIN_FEEDBACK_RESPONSE");
            serverbean.executeService();

            // Go to success page
            String redirectUrl = httpAbsoluteCgiPath + "?IdcService=SS_GET_PAGE&nodeId=" + siteId + "FeedbackForm&fs=1";
            response.sendRedirect(redirectUrl);
            return;
        }
    }

  ---- DON'T THINK YOU WILL NEED ANYTHING PAST HERE ----
Was it helpful?

Solution

So, I believe the issue is that you are pushing to the response and it's committing the response. Once you start pushing the body of the response and it's committed, you can no longer send a redirect because a redirect is achieved via HTTP headers (which is how sendRedirect works).

So, you need to move your form processing 'up' so the sendRedirect occurs earlier.

Optionally, you could try to mess with the auto flush and flush buffer settings: <%@page buffer="xxxkb" autoflush="true" %> but that may not work.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top