这里我只是通过.jsp文件输入用户名和密码,并在不同的行中打印用户名和密码。
package pack123;
public class Loginpg extends HttpServlet{
public void service (HttpServletRequest request, HttpServletResponse response){
PrintWriter pw=response.getWriter();
String username=request.getparameter("uname");
String pass=request.getparameter("pwd");
pw.println("the username is "+username+"\n");
pw.println("the username is "+pass);
}
}
答案 0 :(得分:5)
将servlet执行的结果返回给浏览器,浏览器将输出格式化并显示为HTML。
文本中的HTML换行符(\ n)中的没有任何意义(有关详细信息,请参阅下面的流氓评论)。尝试打印出一个html中断:
<br />
像这样:
pw.println("the username is "+u+"<br />");
pw.println("the username is "+p);
答案 1 :(得分:4)
Newline与HTML无关。事实上,
pw.println("the username is "+u+"\n"); // <-- two new lines.
我想你想要
pw.println("the username is "+u+"<br/>");
即使u
为空,您也会获得一个新行。