首页 > 代码库 > JSONP实例
JSONP实例
JSONP实例
package sus.app;
import java.io.IOException;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;
import org.apache.struts2.interceptor.SessionAware;
import com.opensymphony.xwork2.ActionSupport;
/**
* 登录用户认证
*
* @author Administrator
*
*/
public class AppLoginAction extends ActionSupport
implements SessionAware, ServletRequestAware, ServletResponseAware {
public HttpServletRequest request;
public HttpServletResponse response;
public Map session;
public String callback;
public void setSession(Map session)
{
this.session = session;
}
public void setServletRequest(HttpServletRequest httpServletRequest) {
this.request = httpServletRequest;
}
public void setServletResponse(HttpServletResponse httpServletResponse) {
this.response = httpServletResponse;
}
public String getCallback() {
return callback;
}
public void setCallback(String callback) {
this.callback = callback;
}
@SuppressWarnings({ "unused", "null" })
public String LoginInfoCheck() {
String loginName = request.getParameter("loginName");
String loginPassword = request.getParameter("loginPassword");
StringBuffer _jsonstr = null;
try {
_jsonstr = new StringBuffer();
_jsonstr.append(callback).append("({\"success\":").append("\"true\"").append(",\"result\":");
_jsonstr.append("[]");
} catch (Exception e1) {
e1.printStackTrace();
_jsonstr.append("[]");
}
_jsonstr.append("})");
HttpServletResponse response = ServletActionContext.getResponse();
response.setContentType("text/json;charset=utf-8");
try {
response.getWriter().write(_jsonstr.toString());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
}