flex通过httpservice方式结合struts2,在flex中请求的路径是Struts2的一个action,怎么返回结果到flex页面中,这是Struts2中要调用的方法:
public String flextest() throws Exception
{
HttpServletRequest request = ServletActionContext.getRequest ();
String name1=request.getParameter("username");
String pass1=request.getParameter("password");
User user=loginService.getAuthUsers(name1, pass1);
if(user!=null)
{
return SUCCESS;
}
else
{
return "fail";
}
}
我想把登陆成功的结果返回到felx页面 应该怎么做,哪位高手教教小弟
其实没必要这么做,你可以还按照以前的那个做法,没你想的那么麻烦,你要清楚地知道什么是HTPP,在我理解其实很简单,无非就是请求和响应。也就是说你的在Struts2中配置的页面就是响应。你在AS中都可以到这些响应的信息,即页面信息。说白了你可以得到一个大的字符串就是页面里的全部内容,然后自己在AS中处理这个字符串。但是这个做法不是很友好,本人习惯的做法就是返回一个XML 这样在AS 中他可以自动帮我解析。以上均是个人经验仅供楼主参考。
将SUCCESS 的ResultType定义为Stream 。
试试这样:
[code="java"]
private InputStream inStream;
public InputStream getInStream() throws IOException {
return new ByteArrayInputStream("Success".getBytes("UTF-8"));
}
public String flextest() throws Exception {
HttpServletRequest request = ServletActionContext.getRequest();
String name1 = request.getParameter("username");
String pass1 = request.getParameter("password");
User user = loginService.getAuthUsers(name1, pass1);
if (user != null) {
return SUCCESS;
} else {
return "fail";
}
}[/code]
[code="xml"]
text/plain
inStream
[/code]