ajax servlet端小问题

说是小问题。。。调试了一天气死了

 

代码
   
     
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String username
= request.getParameter( " username " );
String password
= request.getParameter( " password " );
response.setContentType(
" text/html;utf-8 " );
response.setCharacterEncoding(
" utf-8 " );
PrintWriter writer
= response.getWriter();

if ( null != username && null != password) {
if (username.equals( "" ) || password.equals( "" )) {
writer.println(
" don't post empty value " );
}
else {

if (username.equalsIgnoreCase( " xc " ) && password.equalsIgnoreCase( " 123 " )) {
writer.println(
" ok " );
}
else {
writer.println(
" error " );
}
}
response.flushBuffer();
}
}

很简单的提交,返回

ajax servlet端小问题

ok后面直接多了个%0D%0A,

今天才知道,println啊…………………………

全部改成print就对了。。。

你可能感兴趣的:(servlet)