Ext Login,服务端返回后出现页面脚本错误

阅读更多

先看下页面....

<%@ page contentType="text/html;charset=GBK" pageEncoding="GBK" %>





extDemo









 

再看下服务端...

package demo;

import java.io.IOException;
import java.sql.ResultSet;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;


public class LoginServlet extends HttpServlet
{
	public void doGet(HttpServletRequest request,HttpServletResponse response)
		throws ServletException,IOException
	{
		response.setContentType("text/html;charset=gb2312");
		request.setCharacterEncoding("gb2312");
		
		try
		{
			String user=request.getParameter("name");
			String pasd=request.getParameter("pws");
			String flag="";
			
			System.out.println("---------------------user:"+user+"----pwd:"+pasd);
			if(user!=null && !"".equals(user)){
				if(pasd!=null && !"".equals(pasd)){
					DBconnection conn = new DBconnection();
					System.out.println("select * from user u where u.username="+user+" and u.password="+pasd);
					ResultSet rs = conn.getResult("select * from user u where u.username='"+user+"' and u.password='"+pasd+"'");
					
					if(rs.next()){
						flag="0";
					}
				}
			}
			System.out.println("------------flag:"+flag);
			if(flag!=null && !"".equals(flag)){
				//json形式返回数据,如何返回???
				String json = "(success:true,msg:\'ok\')";
				response.getWriter().write(json);
			    response.getWriter().flush();
			    System.out.println(json);
				response.sendRedirect("index.jsp");
			}
			else{
				String json = "(success:true,msg:\'Login fail\')";
				response.getWriter().write(json);
			    response.getWriter().flush();
			    System.out.println(json);
				response.sendRedirect("index.jsp");
			}
		}
		catch(Exception ex){
			
		}
	}
	public void doPost(HttpServletRequest request,HttpServletResponse response)
		throws ServletException,IOException
	{
		doGet(request,response);
	}
}

 

 

问题出在从服务端返回客户端时...页面出现脚本错误...指向页面的第24行...少')'号....哪位朋友知道帮帮忙....先谢了..初学Ext,所用API为2.2版本.

 

另外还想问一下,从服务端回显json格式数据时,以什么方式?是用out,还是write还是其它什么? :)

你可能感兴趣的:(EXT,脚本,json,JavaScript,CSS)