写JSP时的换行问题:
代码如下:
<!-- radiocheck.jsp -->
<%@ page contentType="text/html; charset=utf-8" language="java" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<title>单选按钮与复选框</title>
</head>
<body>
<%
String str1=request.getParameter("radiobutton");
String str2[]=request.getParameterValues("check");
if(str1!=null && str2!=null)
{
//str1=new String(str1.getBytes("ISO-8859-1"),"utf-8");
out.println("你经常使用的是"+str1+"上网<br>");
out.println("经常上网的地方是:");
if(str2!=null)
{
for(int i=0; i<str2.length; i++)
{
out.println(str2[i]+" ");
}
}
}
%>
<form name="form1" method="post" action="">
<p>你使用什么方式上网</p>
<p><input name="radiobutton" type="radio" value="ASDL" checked>ASDL</p>
<p><input name="radiobutton" type="radio" value="拨号上网">拨号上网</p>
<p><input name="radiobutton" type="radio" value="无线接入">无线接入</p>
<p><input name="radiobutton" type="radio" value="DDN专线">DDN专线</p>
<p>你经常在什么地方上网</p>
<p><input name="check" type="checkbox" value="home">home</p>
<p><input name="check" type="checkbox" value="school">school</p>
<p><input name="check" type="checkbox" value="Internet Bar">Internet Bar</p>
<p><input name="submit" type="submit" value="Submit"></p>
</form>
</body>
</html>
out.println()在web上显示出来的不换行。
原因:out.println()相当于在页面写html代码,html代码并不能导致页面显示的换行,还需要在换行的代码后面加上<br>(html的换行是<br>)。
因此:若要换行则需在out.println()中加上<br>。
如代码中:out.println("你经常使用的是"+str1+"上网<br>");
out.println(str1+"br");