Mytitle Myvendor -6ren">
gpt4 book ai didi

java - "getOutputStream() has already been called"在jsp页面内使用jnlp标签时

转载 作者:行者123 更新时间:2023-12-02 11:39:31 30 4
gpt4 key购买 nike

我正在尝试从 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();
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() has already been called for this response

我还知道这个异常是由于编译后的jsp文件中新行的“空格”造成的,因此我还在jsp顶部添加了以下行

<%@ page trimDirectiveWhitespaces="true" %>

但我仍然遇到同样的问题,然后我还做了一些愚蠢的事情,例如手动删除jsp文件中的空格

<%@ page .....%><%@ page.....%>

但仍然是同样的异常。

最佳答案

出现这种情况是因为,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>

关于java - "getOutputStream() has already been called"在jsp页面内使用jnlp标签时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48683306/

30 4 0