我对jsp页面有一个GET请求。 JSP页面的内容如下:
<%@page language="java" import="java.sql.*,java.util.*" %>
<%@page import="javax.servlet.*, java.util.*,java.util.Date, java.text.*"%>
<jsp:useBean id="workM" class="test.concept" scope="page" />
<jsp:useBean id="userM" class="test.learning" scope="page" />
<jsp:useBean id="checkM" class="test.check" scope="session" />
<%
if (checkM.checkUser()) //For auto loading user's most used search engine. Note: Only if the difference between top two is very big
{
String user_id = checkM.getUser();
ResultSet RS6=workM.executeQuery("select top 1 searchEngineUsed,count(*) as number from UserSearchEngineSearch where user_id='"+user_id+"' group by searchEngineUsed order by number desc;");
while (RS6.next())
{
String name = RS6.getString("searchEngineUsed");
if (name.equals("google"))
{
out.print("1");
}
else if (name.equals("yahoo"))
{
out.print("2");
}
else if (name.equals("bing"))
{
out.print("3");
}
else if (name.equals("baidu"))
{
out.print("4");
}
else if (name.equals("yandex"))
{
out.print("5");
}
else if (name.equals("askcom"))
{
out.print("6");
}
else //by default just display google
{
out.print("1");
}
}
}
else //user not login
{
out.print("1");
}
%>
然而,GET网页的内容包含5行新行后跟4(表示&#34; baidu&#34;被选中)。如何删除5行新行间距?
答案 0 :(得分:1)
如果您使用的是Tomcat,则可以使用
<%@ page trimDirectiveWhitespaces="true" %>
在您的网页上,或在web.xml
<jsp-config>
<jsp-property-group>
<url-pattern>*.jsp</url-pattern>
<trim-directive-whitespaces>true</trim-directive-whitespaces>
</jsp-property-group>
</jsp-config>
答案 1 :(得分:0)
JSP顶部的<%@page>
和<jsp:useBean>
指令每个都用换行符分隔。如果您确实想要删除它们,则需要将它们写在一行中。然而,额外的换行不会造成伤害,它们不会被浏览器呈现。
答案 2 :(得分:0)
此外,您可以将其重写为以下内容:
<%@page language="java" import="java.sql.*,java.util.*"
%><%@page import="javax.servlet.*, java.util.*,java.util.Date, java.text.*"
%><jsp:useBean id="workM" class="test.concept" scope="page"
/><jsp:useBean id="userM" class="test.learning" scope="page"
/><jsp:useBean id="checkM" class="test.check" scope="session"
/><%
......
%>
它不会添加任何额外的新行。