Java 在jsp页面内使用jnlp标记时已调用“getOutputStream()
我试图从jsp页面转到jnlp文件,以获得注册用户的指纹, 文件如下所示Java 在jsp页面内使用jnlp标记时已调用“getOutputStream(),java,jsp,jnlp,Java,Jsp,Jnlp,我试图从jsp页面转到jnlp文件,以获得注册用户的指纹, 文件如下所示 <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <% String path = request.getContextPath(); String protocol = request.getScheme(); String domain = request.getServerName();
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
String path = request.getContextPath();
String protocol = request.getScheme();
String domain = request.getServerName();
String port = Integer.toString(request.getServerPort());
String a = protocol + "://" + domain + ":" + port + path;
path = protocol + "://" + domain + ":" + port + path + "/";
%>
<%@page contentType="application/x-java-jnlp-file" pageEncoding="UTF-8"%>
<%@taglib uri="http://www.springframework.org/tags" prefix="spring" %>
<?xml version="1.0" encoding="UTF-8"?>
<jnlp spec="1.0+" codebase="<%=path%>" href="">
<information>
<title>Mytitle</title>
<vendor>Myvendor</vendor>
</information>
<security><all-permissions/></security>
<resources>
<!-- Application Resources -->
<j2se version="1.6+" href="http://java.sun.com/products/auto/j2se"/>
<jar href="jnlp/FingerPrintApplet.jar" main="true"/>
</resources>
<application-desc main-class="ui.InvitationApplet">
<argument>${firstName}</argument>
<argument>${lastName}</argument>
<argument>${loginId}</argument>
<argument>${roleId}</argument>
<argument>${urlCode}</argument>
<argument>${mainRecordOfficer}</argument>
<argument>${middleName}</argument>
<argument>${employeeId}</argument>
<argument>${createdBy}</argument>
<argument><%=a%></argument>
<argument>${invitedUnder}</argument>
<argument>${login_type}</argument>
</application-desc>
</jnlp>
但每次点击jsp页面时,jnlp都会被下载,但我会遇到异常
java.lang.IllegalStateException:已为此响应调用getOutputStream
我还了解到,这个异常是由于编译的jsp文件中新行的空格造成的,因为我还在jsp文件顶部的行下方添加了空格
<%@ page trimDirectiveWhitespaces="true" %>
但我还是遇到了同样的问题,然后我还做了一些愚蠢的事情,比如手动删除jsp文件中的空格,比如
<%@ page .....%><%@ page.....%>
但还是一样的例外。
感谢advanced提供了精确的解决方案。之所以会出现这种情况,是因为jsp页面中默认保留了空格,空格可能会作为一行添加到输出中,所以上面解释的异常情况会出现,为了消除这种情况,只需在web.xml中添加以下行,这应该得到修复
<jsp-config>
<jsp-property-group>
<url-pattern>*.jsp</url-pattern>
<trim-directive-whitespaces>true</trim-directive-whitespaces>
</jsp-property-group>
</jsp-config>