1. 程式人生 > >jsp中的session在java檔案中取到

jsp中的session在java檔案中取到

jsp頁面呼叫.mxml頁面,然後.mxml頁面呼叫後臺java檔案,在後臺java檔案中通過session 可以取道jsp頁面中的session的值.

<%@ page language="java" import="java.util.*,com.xbzc.phr.service.login.*" pageEncoding="utf-8"%>
<%
	String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'index.jsp' starting page</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
  </head>
  <body>
  
<%

String sid = request.getParameter("systemId");  //市級平臺上註冊的系統ID
String pwd = request.getParameter("password");  //市級平臺上註冊的系統密碼
String did = request.getParameter("doctorUserId");  //醫生ID
String dname = new String(request.getParameter("doctorUserName").getBytes("ISO-8859-1"));  //醫生姓名
String unid = request.getParameter("uniqueId");  //患者註冊的唯一內部標識
String idtype = request.getParameter("idTypeCode");  //患者註冊的唯一內部標識型別
String vipo = request.getParameter("userRole");  // 檢視角色viewPole
String vitar = request.getParameter("purposeOfRuse"); //檢視目的viewTarget

String patiName = request.getParameter("patientName"); 
String patiSex = request.getParameter("patientSex");  
String patiBirthDate = request.getParameter("patientBirthDate"); 

session.setAttribute("doctorUserId",did);   // 醫生ID
session.setAttribute("doctorUserName",dname);   // 醫生姓名
session.setAttribute("uniqueId",unid);   // 患者註冊的唯一內部標識
session.setAttribute("idTypeCode",idtype);   // 患者註冊的唯一內部標識
session.setAttribute("systemId",sid);   // 市級平臺上註冊的系統ID
session.setAttribute("password",pwd);   // 市級平臺上註冊的系統密碼
session.setAttribute("viewPole",vipo);  // 檢視角色
session.setAttribute("viewTarget",vitar); //檢視目的
session.setAttribute("patientName",patiName);
session.setAttribute("patientSex",patiSex);
session.setAttribute("patientBirthDate",patiBirthDate);

%>
	<jsp:forward page="PHBEMR.html"/>

  </body>
</html>


上面的PHBEMR.html 其實是 PHBEMR.mxml,在 PHBEMR.mxml中呼叫了後臺的java,

public RPCMessage getURLParameter() {
		log.info("服務層操作:返回第三方傳過來的引數,第三方設定的引數在index.jsp中  getURLParameter()");
		// log.info("驗證[" + userId + "]共享資訊");
		HttpServletRequest request = FlexContext.getHttpRequest();
		HttpSession session = request.getSession();
		List<TURLParameterDTO> urlParameterList = new ArrayList<TURLParameterDTO>();
		// Map<String,TURLParameterDTO> map = new
		// HashMap<String,TURLParameterDTO>();
		TURLParameterDTO o = null;
		String idNumber = "";
		String idTypeCode = "";
		String uniqueId = (String) SessionUtils.getAttribute("uniqueId");
		try {
			Enumeration<String> enumeration = (Enumeration<String>) session
					.getAttributeNames();
			String attributeName;
			while (enumeration.hasMoreElements()) {
				attributeName = enumeration.nextElement().toString();
				if (("__flexSession".equals(attributeName))
						|| ("currentuser".equals(attributeName)))
					continue;

				o = new TURLParameterDTO();
				o.setPropertykey(attributeName);
				o.setPropertyvalue((String) session.getAttribute(attributeName));


上面的程式碼中拿到了session中的值.

=============================================

flex呼叫java也存在request請求,

HttpServletRequest request = FlexContext.getHttpRequest();  //   flex.messaging.FlexContext

然後通過request能拿到session

HttpSession session = request.getSession();   //  javax.servlet.http.HttpSession