문제

할 수 있는 방법 스트립에서 여분의 공백 jsp 페이지의 출력?가 스위치를 내 뒤에서 나 web.xml?이 있는 Tomcat 의 특정 설정은?

도움이 되었습니까?

해결책

가 trimWhiteSpaces 지시어는 이를 위해,

에서 당신의 JSP:

<%@ page trimDirectiveWhitespaces="true" %>

또는 jsp-config 섹션 web.xml (이 작품에서 출발블릿 사양 2.5.):

<jsp-config>
  <jsp-property-group>
    <url-pattern>*.jsp</url-pattern>
    <trim-directive-whitespaces>true</trim-directive-whitespaces>
  </jsp-property-group>
</jsp-config>

불행하게도 있을 경우 필요한 공간을 수도 있습니다 필요는,그래서 당신은 당신이 필요할 수 있습 non-을 깨고 공간에 일치합니다.

다른 팁

하는 경우 servletcontainer 지원하지 않 JSP2.1 trimDirectiveWhitespaces 제공,당신은 필요한 상담을 그 JspServlet 문서에 대한 모든 초기화를 매개 변수입니다.에 대한 예 Tomcat, 구성할 수 있습니다뿐만 아니라 그것에 의해 설정 trimSpaces init-param 하기 true 에 대 JspServlet 톰캣의 /conf/web.xml:

<init-param>
    <param-name>trimSpaces</param-name>
    <param-value>true</param-value>
</init-param>

완전히 다른 대안은 JTidyFilter.그렇지만 손질 공백하지만,그것은 또한 형식 HTML 에 올바른 들여쓰기가 있습니다.

이 trimDirectiveWhitespaces 에서만 지원됩 servlet 을 지원하는 컨테이너 JSP2.1 이후,또는 경우 또는 Tomcat,Tomcat6(그리고 일부 버전에 예:Tomcat6.0.10 지 않아 그것을 구현하 제대로 알지 못에 대해 다른 사람).더 많은 정보에 대해 trimDirectiveWhitespaces 여기:

http://www.oracle.com/technetwork/articles/javaee/jsp-21-136414.html

그리고 여기에

http://raibledesigns.com/rd/entry/trim_spaces_in_your_jsp1

만약 당신이 태그를 사용하여 적용할 수 있습니다 너무 거기:

<%@ tag description="My Tag" trimDirectiveWhitespaces="true" %>

과에서 당신의 jsp:

<%@ page trimDirectiveWhitespaces="true" %>

지 않을 직접 당신이 무엇을 요구하지만,무엇을 도어에 HTML 태그에서 이 영리한 방법으로 내 jsp 태그,또한 퍼팅 공백 안에 servlet 태그(<%%>):

${"<!--"}
<c:if test="${first}">
    <c:set var="extraClass" value="${extraClass} firstRadio"/>
</c:if>
<c:set var="first" value="${false}"/>
${"-->"}<%

%><input type="radio" id="input1" name="dayChooser" value="Tuesday"/><%
%><label for="input1" class="${extraClass}">Tuesday</label>

추가/수정 톰캣 catalina.properties 파일

org.apache.jasper.compiler.Parser.STRICT_QUOTE_ESCAPING=false

도 참조하십시오: https://confluence.sakaiproject.org/display/BOOT/Install+Tomcat+7

할 수 있 한 단계 더 나아가도바꿈(포함합니다)간에 html 태그를 구축 시간입니다.

E.g.변경:

<p>Hello</p>
<p>How are you?</p>

으로:

<p>Hello</p><p>How are you?</p>

지 않는,사용 maven-replacer-plugin 에 그것을 설정 pom.xml:

<plugin>
    <groupId>com.google.code.maven-replacer-plugin</groupId>
    <artifactId>replacer</artifactId>
    <version>1.5.3</version>
    <executions>
        <execution>
            <id>stripNewlines</id>
            <phase>prepare-package</phase>
            <goals>
                <goal>replace</goal>
            </goals>
            <configuration>
                <basedir>${project.build.directory}</basedir>
                <filesToInclude>projectname/WEB-INF/jsp/**/*.jsp</filesToInclude>
                <token>&gt;\s*&lt;</token>
                <value>&gt;&lt;</value>
                <regexFlags>
                    <regexFlag>MULTILINE</regexFlag>
                </regexFlags>
            </configuration>
        </execution>
    </executions>
</plugin>

이 것만 수정하는 Jsp 를 만드는 디렉토리를 만지지 Jsp 에서는 소스입니다.

필요할 수 있는 적응하는 경로(<filesToInclude>)는 Jsp 있습니다.

사용하십시오 트림 funcion,예

fn:trim(string1)
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top