flex页面传参另种解决方式

大致意思就是:

方法1:登陆的时候 通过http请求 ,服务器会吧user放进session中

session.setAttribute("user",user);

再另个页面需要这个参数时,使用remoteObject,我用的blazeds,

使用User user=FlexContent.getSesion("user"),返回给第2个页面的flex程序。 (请求getRequest应该也行,我没用),

方法2:我之前发的在jsp中动态编译 运行mxml   http://fykyx521.iteye.com/admin/blogs/375285

var user:User=<%request.getAttribute("user")%>

 

贴点代码:

//登陆后吧user保存到session中
public void service(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException{
		response.setContentType("text/html");
		
		//  request.getRequestDispatcher("carinfo.jsp").forward(request,response);   
		String username=request.getParameter("username");
		String password=request.getParameter("password");
		if("".equals(username)||"".equals(password)){
			response.sendRedirect("../login_register.html");
		}else{
			User user=new User(username,password);
			
			User hasUser=userUtil.getUser(user);
			System.out.println("selectId"+hasUser.getId()+"______name:"+hasUser.getRoleName());
			if(hasUser!=null){
				HttpSession session=request.getSession(true);
				session.setAttribute("user", hasUser);
//				 this.redirect(response, "../test1.html");
				if(hasUser.getRoleName()!=null){
//					 this.redirect(response, "../test1.html");
					response.sendRedirect("../myRpg.jsp");
				}else{
					response.sendRedirect("../choose.jsp");
				}
			}else{
				response.sendRedirect("../login_register.html");
			}
		}
		
		
	}

 

另一个页面从服务器取session中的数据
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init()">
	<mx:RemoteObject id="roleName" destination="roleName" endpoint="http://192.168.200.14:8080/J2EE/messagebroker/amf">
		
	</mx:RemoteObject>
	<mx:Script>
		<![CDATA[
			import mx.controls.Alert;
			import mx.rpc.events.ResultEvent;
			import mx.rpc.events.FaultEvent;
			
			public function init(){
				roleName.getRoleName();
				roleName.addEventListener(ResultEvent.RESULT,onRemoteResult);
				roleName.addEventListener(FaultEvent.FAULT,error);
			}
			 public function onRemoteResult(event:ResultEvent){
		    	mx.controls.Alert.show("result"+event.result.toString());
		     }
		     public function error(event:FaultEvent){
		     	mx.controls.Alert.show(event.message.toString());
		     }
		]]>
	</mx:Script>
</mx:Application>

   服务器端代码

 

public String getRoleName(){
		HttpSession session=FlexContext.getHttpRequest().getSession(false);
		
		User user=(User)session.getAttribute("user");
		
		System.out.println("user:"+user);
		System.out.println("userRemote:"+user.getRoleName());
		return user.getRoleName();
		
	}

  remote-config.xml

 

<destination id="roleName">
		<properties>
			<source>
				Main.MyService
			</source>
		</properties>
	</destination>
 

 

你可能感兴趣的:(html,jsp,xml,Flex,Adobe)