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;
}
}
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。