Using the SSH framework to do the project can not avoid the use of the session, sometimes the use of the session will be very convenient, but sometimes it is a very troublesome thing, I encountered a situation today, I am very uncomfortable, or record it.
The first is to log in, if the user name password is correct to put the user's information into the session,
// Save user information to session after successful login Sessionutils.setsysusertosession (Request, Sysuser);
/*** Save the current logged-in user's information to the session *@paramRequest *@paramSysuser*/ Public Static voidsetsysusertosession (httpservletrequest request, Sysuser Sysuser) {HttpSession session=request.getsession (); if(sysuser==NULL){ return; } session.setattribute ("Sysuserkey", Sysuser); }
After successful login, a modal window should pop up on a page, add a department information to the modal window, then close the modal window and display the data list on the page.
The Display data list takes the form of jquery and Ajax federated asynchronous loading, that is, using AJAX to fetch data from the background in $ (function () {}), and then back to the foreground in JSON, where the specific data is given to the columns that correspond to the table.
At the beginning of the pop-up modal window is no problem, add a piece of data is not a problem, but after closing the modal window data list is not updated, you must refresh before you can see the data in the list of the message added to the data,
At first, I thought it was the problem of pop-up modal window, also thought is the problem of page cache, anyway is a variety of tangled ah, but then unconsciously saw the backstage code to think of the crux of the problem, the following first resolved code:
<script type= "Text/javascript" >$ (function () {//alert ("0000"); //Loading organization Information asynchronously$.ajax ({URL:"User/organizaaction_selectallorg.do", type:"POST", DataType:"JSON", Cache:false, Success:function (DA) {$ ("#orgTbody"). empty (); $.each (Da,function (index,value) {if(value.owner==Value.currentuser) {var tr= "<tr>" + "<td>" +value.orgname+ "</td>" + "<td>" +value.owner+ "</td>" + "<td>" +value.orgremark+ "</TD&G t; "+" <td> "+" <a class= ' btn Btn-defau Lt ' onclick= ' showmodal ("+value.id+") ' href= ' javascript:; ' ><i class= ' FA fa-cog ' ></i> settings </a> ' + ' <a class= ' btn btn-def Ault ' href= ' javascript:; ' onclick= ' Showuser ("+value.id+") ' ><i class= ' FA Fa-male ' ></i> organization members </a> "+" </td> "+" </tr> "; }Else{var tr= "<tr>" + "<td>" +value.orgname+ "</td>" + "<td>" +value.owner+ "</td>" + "<td>" +value.orgremark+ "</TD&G t; "+" <td> "+" <a class= ' btn Btn-defau Lt ' href= ' javascript:; ' ><i class= ' FA fa-sign-in ' ></i> exit </a> ' + ' <a class= ' btn btn -default ' href= ' javascript:; ' ><i class= ' FA Fa-male ' ></i> organization members </a> "+" </td> "+ "</tr>"; } $("#orgTbody"). Append (tr); }); } }); }); </SCRIPT>
This is the asynchronous loading of JS
Public voidselectallorg () {Sysuser Sysuser=sessionutils.getsysuserfromsession (Request); Integer ID=Sysuser.getid (); Sysuser Curuser=Sysuserservice.findsysuserbyid (ID); Set<Organization> setlist=curuser.getorganizations (); orgutil org; List<OrgUtil> orglist=NewArraylist<orgutil>(); for(Organization o:setlist) {org=NewOrgutil (); Org.setid (O.getid ()); Org.setorgname (O.getorgname ()); Org.setorgremark (O.getorgremark ()); Org.setowner (O.getowner ()); Org.setcurrentuser (Sysuser.getcnname ()); Orglist.add (org); } Writejson (Orglist); }
This is the background to find all the information of the code, where is the key? Just in
Sysuser sysuser=sessionutils.getsysuserfromsession (request); Integer id=sysuser.getid (); Sysuser curuser=sysuserservice.findsysuserbyid (ID);
In these three lines of code, the beginning of the time is not to find the user's two lines of code, directly from the session to remove the user, and then based on the user to find out.
The reason why cannot find out is because: the user who comes from the session is logged in time user, at this time this user is not related to your new department, so is not to find the new department, only to re-load the user to get the new department information.
Well, that's it for the time being.
Session problem in SSH framework