From fc925fae71714230b6056ba0e72ee3dea166e4da Mon Sep 17 00:00:00 2001 From: Tommy Wang Date: Fri, 24 Sep 2010 14:00:11 +0800 Subject: [PATCH] =?utf8?q?=E4=BF=AE=E6=94=B9Servlet=E5=88=AB=E5=90=8D?= =?utf8?q?=EF=BC=8C=E5=B9=B6=E8=A7=A3=E5=86=B3tomcat=E4=B8=8Bresponse?= =?utf8?q?=E7=9A=84cache=E9=97=AE=E9=A2=98=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../java/org/gaixie/jibu/itest/DeployWarIT.java | 6 +++--- .../gaixie/jibu/security/servlet/LoginFilter.java | 6 +++++- .../gaixie/jibu/security/servlet/LoginServlet.java | 18 +++++++++--------- .../security/servlet/SecurityServletModule.java | 12 ++++++------ .../src/main/resources/dbscripts/derby/patch01.sql | 4 ++-- .../src/main/webapp/js/classic/layout.js | 2 +- .../webapp/js/system/administration/authority.js | 8 ++++---- .../src/main/webapp/js/system/administration/pm.js | 22 +++++++++++----------- .../main/webapp/js/system/administration/role.js | 10 +++++----- .../main/webapp/js/system/administration/user.js | 8 ++++---- .../src/main/webapp/js/system/setting.js | 10 +++++----- .../jibu/security/servlet/LoginServletTest.java | 2 +- .../jibu/security/servlet/MainServletTest.java | 4 ++-- 13 files changed, 58 insertions(+), 54 deletions(-) diff --git a/itest/war-itest-suite/src/test/java/org/gaixie/jibu/itest/DeployWarIT.java b/itest/war-itest-suite/src/test/java/org/gaixie/jibu/itest/DeployWarIT.java index 3abd038..395e1f5 100644 --- a/itest/war-itest-suite/src/test/java/org/gaixie/jibu/itest/DeployWarIT.java +++ b/itest/war-itest-suite/src/test/java/org/gaixie/jibu/itest/DeployWarIT.java @@ -54,13 +54,13 @@ public class DeployWarIT { // 不要在加载 ajax 文件时报错,这里不对js文件做测试,也不会调用。 HttpUnitOptions.setExceptionsThrownOnScriptError(false); WebConversation wc = new WebConversation(); - WebRequest req = new GetMethodWebRequest( "http://localhost:8080/LoginServlet.x" ); + WebRequest req = new GetMethodWebRequest( "http://localhost:8080/Login.x" ); req.setParameter("ci","login"); req.setParameter("username","admin"); req.setParameter("password","123456"); WebResponse wr = wc.getResponse(req); - req = new PostMethodWebRequest( "http://localhost:8080/UserServlet.z" ); + req = new PostMethodWebRequest( "http://localhost:8080/User.z" ); req.setParameter("ci","userAdd"); req.setParameter("User.username","tommy"); req.setParameter("User.password","123456"); @@ -70,7 +70,7 @@ public class DeployWarIT { wr = wc.getResponse(req); String email = null; - req = new PostMethodWebRequest( "http://localhost:8080/UserServlet.z" ); + req = new PostMethodWebRequest( "http://localhost:8080/User.z" ); req.setParameter("ci","userFind"); req.setParameter("User.username",""); req.setParameter("User.password",""); diff --git a/jibu-web/jibu-core-extjs/src/main/java/org/gaixie/jibu/security/servlet/LoginFilter.java b/jibu-web/jibu-core-extjs/src/main/java/org/gaixie/jibu/security/servlet/LoginFilter.java index fa98aa7..657676e 100644 --- a/jibu-web/jibu-core-extjs/src/main/java/org/gaixie/jibu/security/servlet/LoginFilter.java +++ b/jibu-web/jibu-core-extjs/src/main/java/org/gaixie/jibu/security/servlet/LoginFilter.java @@ -60,9 +60,13 @@ import javax.servlet.http.HttpSession; } if (!allowedRequest) { - ((HttpServletResponse) res).sendRedirect("/"); + ((HttpServletResponse) res).sendRedirect("Login.x"); return; } + //不要cache 通过此Filter的response。 + //http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html + ((HttpServletResponse)res).setHeader("Pragma", "no-cache"); + ((HttpServletResponse)res).setHeader("Cache-Control","no-cache,no-store,max-age=0"); chain.doFilter(req, res); } diff --git a/jibu-web/jibu-core-extjs/src/main/java/org/gaixie/jibu/security/servlet/LoginServlet.java b/jibu-web/jibu-core-extjs/src/main/java/org/gaixie/jibu/security/servlet/LoginServlet.java index 3730ede..bdc90f3 100644 --- a/jibu-web/jibu-core-extjs/src/main/java/org/gaixie/jibu/security/servlet/LoginServlet.java +++ b/jibu-web/jibu-core-extjs/src/main/java/org/gaixie/jibu/security/servlet/LoginServlet.java @@ -90,7 +90,7 @@ import org.slf4j.LoggerFactory; // check if we have a session HttpSession ses = req.getSession(true); ses.setAttribute("username", username); - resp.sendRedirect("MainServlet.y"); + resp.sendRedirect("Main.y"); } catch (LoginException le) { loadPage(req,resp,"login.message.001"); } @@ -109,7 +109,7 @@ import org.slf4j.LoggerFactory; if("sessionExpired".equals(reason)) { loadPage(req,resp,"login.message.010"); } else { - resp.sendRedirect("/"); + resp.sendRedirect("Login.x"); } } @@ -120,7 +120,7 @@ import org.slf4j.LoggerFactory; if (ses != null) { String username = (String)ses.getAttribute("username"); if (username != null) { - resp.sendRedirect("MainServlet.y"); + resp.sendRedirect("Main.y"); return; } } @@ -137,7 +137,7 @@ import org.slf4j.LoggerFactory; sb.append(rb.getString(message)); sb.append(" "); } - sb.append("
\n"+ + sb.append(" \n"+ "

\n"+ " \n"+ "

\n"+ " \n"+ - " "+rb.getString("login.lostpassword")+"\n"+ + " "+rb.getString("login.lostpassword")+"\n"+ "
\n"); sb.append(""); @@ -175,7 +175,7 @@ import org.slf4j.LoggerFactory; sb.append(message); // 如果操作成功,不再显示 from,失败才显示。 if (showForm) { - sb.append("
\n"+ + sb.append(" \n"+ "

\n"+ "

"+rb.getString("login.backtologin")+"

\n"); + sb.append("

"+rb.getString("login.backtologin")+"

\n"); } sb.append(""); @@ -279,7 +279,7 @@ import org.slf4j.LoggerFactory; sb.append(message); // 如果操作成功,不再显示 from,失败才显示。 if (showForm) { - sb.append("
\n"+ + sb.append(" \n"+ " \n"+ "

\n"+ "

"+rb.getString("login.backtologin")+"

\n"); + sb.append("

"+rb.getString("login.backtologin")+"

\n"); } sb.append(""); diff --git a/jibu-web/jibu-core-extjs/src/main/java/org/gaixie/jibu/security/servlet/SecurityServletModule.java b/jibu-web/jibu-core-extjs/src/main/java/org/gaixie/jibu/security/servlet/SecurityServletModule.java index d362957..585d653 100644 --- a/jibu-web/jibu-core-extjs/src/main/java/org/gaixie/jibu/security/servlet/SecurityServletModule.java +++ b/jibu-web/jibu-core-extjs/src/main/java/org/gaixie/jibu/security/servlet/SecurityServletModule.java @@ -35,11 +35,11 @@ public class SecurityServletModule extends ServletModule { @Override protected void configureServlets() { filter("*.y","*.z").through(LoginFilter.class); serve("/").with(LoginServlet.class); - serve("/LoginServlet.x").with(LoginServlet.class); - serve("/MainServlet.y").with(MainServlet.class); - serve("/SettingServlet.y").with(SettingServlet.class); - serve("/UserServlet.z").with(UserServlet.class); - serve("/AuthorityServlet.z").with(AuthorityServlet.class); - serve("/RoleServlet.z").with(RoleServlet.class); + serve("/Login.x").with(LoginServlet.class); + serve("/Main.y").with(MainServlet.class); + serve("/Setting.y").with(SettingServlet.class); + serve("/User.z").with(UserServlet.class); + serve("/Authority.z").with(AuthorityServlet.class); + serve("/Role.z").with(RoleServlet.class); } } \ No newline at end of file diff --git a/jibu-web/jibu-core-extjs/src/main/resources/dbscripts/derby/patch01.sql b/jibu-web/jibu-core-extjs/src/main/resources/dbscripts/derby/patch01.sql index 505e2a4..7ff69c6 100644 --- a/jibu-web/jibu-core-extjs/src/main/resources/dbscripts/derby/patch01.sql +++ b/jibu-web/jibu-core-extjs/src/main/resources/dbscripts/derby/patch01.sql @@ -1,5 +1,5 @@ -insert into authorities (name,value) values ('system.administration.pm','RoleServlet.z'); -insert into authorities (name,value) values ('system.setting','SettingServlet.y'); +insert into authorities (name,value) values ('system.administration.pm','Role.z'); +insert into authorities (name,value) values ('system.setting','Setting.y'); insert into settings (name,value,sortindex,enabled) values ('theme','blue',0,1); insert into settings (name,value,sortindex,enabled) values ('theme','gray',1,1); diff --git a/jibu-web/jibu-core-extjs/src/main/webapp/js/classic/layout.js b/jibu-web/jibu-core-extjs/src/main/webapp/js/classic/layout.js index 3ba6635..5715645 100644 --- a/jibu-web/jibu-core-extjs/src/main/webapp/js/classic/layout.js +++ b/jibu-web/jibu-core-extjs/src/main/webapp/js/classic/layout.js @@ -19,7 +19,7 @@ jibu.layout.classic.HeaderPanel = function(){ tooltip: this.exitText, iconCls :'exit', handler : function() { - window.location = 'LoginServlet.x?ci=logout'; + window.location = 'Login.x?ci=logout'; } }] }); diff --git a/jibu-web/jibu-core-extjs/src/main/webapp/js/system/administration/authority.js b/jibu-web/jibu-core-extjs/src/main/webapp/js/system/administration/authority.js index ffd354a..5656e97 100644 --- a/jibu-web/jibu-core-extjs/src/main/webapp/js/system/administration/authority.js +++ b/jibu-web/jibu-core-extjs/src/main/webapp/js/system/administration/authority.js @@ -54,9 +54,9 @@ Ext.extend(jibu.security.authority.Form, Ext.FormPanel, { var authid = this.getForm().findField('Authority.id').getValue(); var url; if (authid.length > 0) { - url = 'AuthorityServlet.z?ci=authUpdate'; + url = 'Authority.z?ci=authUpdate'; } else { - url = 'AuthorityServlet.z?ci=authAdd'; + url = 'Authority.z?ci=authAdd'; } this.getForm().submit( @@ -83,7 +83,7 @@ jibu.security.authority.Grid = function(config){ this.store = new Ext.data.JsonStore({ // destroy the store if the grid is destroyed autoDestroy: true, - url: 'AuthorityServlet.z?ci=authFind', + url: 'Authority.z?ci=authFind', root: 'data', fields: [ {name: 'id', type: 'int'}, @@ -248,7 +248,7 @@ Ext.extend(jibu.security.authority.Grid,Ext.grid.GridPanel,{ if (btn == 'yes') { Ext.Ajax.request( { - url:'AuthorityServlet.z?ci=authDelete', + url:'Authority.z?ci=authDelete', params:{ 'id':record.get('id') }, diff --git a/jibu-web/jibu-core-extjs/src/main/webapp/js/system/administration/pm.js b/jibu-web/jibu-core-extjs/src/main/webapp/js/system/administration/pm.js index 640fd28..41eb360 100644 --- a/jibu-web/jibu-core-extjs/src/main/webapp/js/system/administration/pm.js +++ b/jibu-web/jibu-core-extjs/src/main/webapp/js/system/administration/pm.js @@ -138,7 +138,7 @@ jibu.security.PM = var ck = this.rolePanel.getChecked(); Ext.Ajax.request( { - url:'RoleServlet.z?ci=bindUser', + url:'Role.z?ci=bindUser', params:{ 'user.id':record.data.id, 'role.id':ck[0].id @@ -170,7 +170,7 @@ jibu.security.PM = var ck = this.rolePanel.getChecked(); Ext.Ajax.request( { - url:'RoleServlet.z?ci=unbindUser', + url:'Role.z?ci=unbindUser', params:{ 'user.id':record.data.id, 'role.id':ck[0].id @@ -228,7 +228,7 @@ jibu.security.PM = if (this.fromwhere=='' || this.fromwhere=='user') { Ext.Ajax.request( { - url:'RoleServlet.z?ci=userBindCheck', + url:'Role.z?ci=userBindCheck', params:{ 'username':this.userSM.getSelected().get('username')}, method:'POST', @@ -320,7 +320,7 @@ jibu.security.PM = var ck = this.rolePanel.getChecked(); Ext.Ajax.request( { - url:'RoleServlet.z?ci=bindAuth', + url:'Role.z?ci=bindAuth', params:{ 'authority.id':record.data.id, 'role.id':ck[0].id @@ -351,7 +351,7 @@ jibu.security.PM = var ck = this.rolePanel.getChecked(); Ext.Ajax.request( { - url:'RoleServlet.z?ci=unbindAuth', + url:'Role.z?ci=unbindAuth', params:{ 'authority.id':record.data.id, 'role.id':ck[0].id @@ -409,7 +409,7 @@ jibu.security.PM = if (this.fromwhere=='' || this.fromwhere=='auth') { Ext.Ajax.request( { - url:'RoleServlet.z?ci=authBindCheck', + url:'Role.z?ci=authBindCheck', params:{ 'id':this.authSM.getSelected().get('id')}, method:'POST', @@ -470,7 +470,7 @@ jibu.security.PM = var ck = this.rolePanel.getChecked(); Ext.Ajax.request( { - url:'RoleServlet.z?ci=roleBindCheck', + url:'Role.z?ci=roleBindCheck', params:{ 'id':ck[0].id}, method:'POST', @@ -572,9 +572,9 @@ jibu.security.PM = if (this.fromwhere=='user' ) { var url; if(b) { - url = 'RoleServlet.z?ci=bindUser'; + url = 'Role.z?ci=bindUser'; } else { - url = 'RoleServlet.z?ci=unbindUser'; + url = 'Role.z?ci=unbindUser'; } Ext.Ajax.request( @@ -617,9 +617,9 @@ jibu.security.PM = if (this.fromwhere=='auth') { var url; if(b) { - url = 'RoleServlet.z?ci=bindAuth'; + url = 'Role.z?ci=bindAuth'; } else { - url = 'RoleServlet.z?ci=unbindAuth'; + url = 'Role.z?ci=unbindAuth'; } Ext.Ajax.request( { diff --git a/jibu-web/jibu-core-extjs/src/main/webapp/js/system/administration/role.js b/jibu-web/jibu-core-extjs/src/main/webapp/js/system/administration/role.js index ca2a1c7..c05b533 100644 --- a/jibu-web/jibu-core-extjs/src/main/webapp/js/system/administration/role.js +++ b/jibu-web/jibu-core-extjs/src/main/webapp/js/system/administration/role.js @@ -65,9 +65,9 @@ Ext.extend(jibu.security.role.Form, Ext.FormPanel, { var rid = this.getForm().findField("Role.id").getValue(); var url; if (rid.length > 0) { - url = 'RoleServlet.z?ci=roleUpdate'; + url = 'Role.z?ci=roleUpdate'; } else { - url = 'RoleServlet.z?ci=roleAdd'; + url = 'Role.z?ci=roleAdd'; } this.getForm().submit( @@ -97,7 +97,7 @@ jibu.security.role.CheckTree = function(config){ this.listeners = { render: function(n) { Ext.Ajax.request({ - url:'RoleServlet.z?ci=getAllRole', + url:'Role.z?ci=getAllRole', method:'POST', success: function(r,a){ //Ext.Msg.alert('信息2',r.responseText); @@ -178,7 +178,7 @@ Ext.extend(jibu.security.role.CheckTree,Ext.tree.TreePanel,{ loadRoleFn : function(btn,event){ Ext.Ajax.request({ - url:'RoleServlet.z?ci=getAllRole', + url:'Role.z?ci=getAllRole', method:'POST', success: function(r,a){ //Ext.Msg.alert('信息2',r.responseText); @@ -248,7 +248,7 @@ Ext.extend(jibu.security.role.CheckTree,Ext.tree.TreePanel,{ if (btn == 'yes') { Ext.Ajax.request( { - url:'RoleServlet.z?ci=roleDelete', + url:'Role.z?ci=roleDelete', params:{ 'id':ck[0].id }, diff --git a/jibu-web/jibu-core-extjs/src/main/webapp/js/system/administration/user.js b/jibu-web/jibu-core-extjs/src/main/webapp/js/system/administration/user.js index e09099f..73a1688 100644 --- a/jibu-web/jibu-core-extjs/src/main/webapp/js/system/administration/user.js +++ b/jibu-web/jibu-core-extjs/src/main/webapp/js/system/administration/user.js @@ -82,9 +82,9 @@ Ext.extend(jibu.security.user.Form, Ext.FormPanel, { var uid = this.getForm().findField('User.id').getValue(); var url; if (uid.length > 0) { - url = 'UserServlet.z?ci=userUpdate'; + url = 'User.z?ci=userUpdate'; } else { - url = 'UserServlet.z?ci=userAdd'; + url = 'User.z?ci=userAdd'; } this.getForm().submit( @@ -112,7 +112,7 @@ jibu.security.user.Grid = function(config){ // destroy the store if the grid is destroyed autoDestroy: true, remoteSort : true, - url: 'UserServlet.z?ci=userFind', + url: 'User.z?ci=userFind', root: 'data', fields: [ {name: 'id', type: 'int'}, @@ -298,7 +298,7 @@ Ext.extend(jibu.security.user.Grid,Ext.grid.GridPanel,{ if (btn == 'yes') { Ext.Ajax.request( { - url:'UserServlet.z?ci=userDelete', + url:'User.z?ci=userDelete', params:{ 'id':record.get('id') }, diff --git a/jibu-web/jibu-core-extjs/src/main/webapp/js/system/setting.js b/jibu-web/jibu-core-extjs/src/main/webapp/js/system/setting.js index 9b15bfc..45c8c14 100644 --- a/jibu-web/jibu-core-extjs/src/main/webapp/js/system/setting.js +++ b/jibu-web/jibu-core-extjs/src/main/webapp/js/system/setting.js @@ -83,7 +83,7 @@ jibu.security.setting.Form = store:new Ext.data.JsonStore({ fields:[{name:'id', type:'int'}, {name:'value', type:'string'}], - url:'SettingServlet.y?ci=settingLoad', + url:'Setting.y?ci=settingLoad', root:'settings', baseParams:{'settings.name' :'language'} }), @@ -100,7 +100,7 @@ jibu.security.setting.Form = store:new Ext.data.JsonStore({ fields:[{name:'id', type:'int'}, {name:'value', type:'string'}], - url:'SettingServlet.y?ci=settingLoad', + url:'Setting.y?ci=settingLoad', root:'settings', baseParams:{'settings.name' :'layout'} }), @@ -117,7 +117,7 @@ jibu.security.setting.Form = store:new Ext.data.JsonStore({ fields:[{name:'id', type:'int'}, {name:'value', type:'string'}], - url:'SettingServlet.y?ci=settingLoad', + url:'Setting.y?ci=settingLoad', root:'settings', baseParams:{ 'settings.name' :'theme' @@ -142,7 +142,7 @@ jibu.security.setting.Form = formBind:true, handler:function() { this.getForm().submit({ - url: 'SettingServlet.y?ci=settingUpdate', + url: 'Setting.y?ci=settingUpdate', method: 'POST', waitMsg: this.waitMsgText, success: function(form, action) { @@ -157,7 +157,7 @@ jibu.security.setting.Form = render:function(){ this.form.load( { - url: 'SettingServlet.y?ci=formLoad', + url: 'Setting.y?ci=formLoad', success:function(f,a){ var settings = a.result.settings; // f.setValues() 会把显示值和实际值都置为 settings[i].value diff --git a/jibu-web/jibu-core-extjs/src/test/java/org/gaixie/jibu/security/servlet/LoginServletTest.java b/jibu-web/jibu-core-extjs/src/test/java/org/gaixie/jibu/security/servlet/LoginServletTest.java index 604876e..199eb63 100644 --- a/jibu-web/jibu-core-extjs/src/test/java/org/gaixie/jibu/security/servlet/LoginServletTest.java +++ b/jibu-web/jibu-core-extjs/src/test/java/org/gaixie/jibu/security/servlet/LoginServletTest.java @@ -65,7 +65,7 @@ public class LoginServletTest { HttpSession ses = (HttpSession) EasyMock.createMock(HttpSession.class); ses.setAttribute("username", "admin"); EasyMock.expect(mockRequest.getSession(true)).andReturn(ses); - mockResponse.sendRedirect("MainServlet.y"); + mockResponse.sendRedirect("Main.y"); //回放 EasyMock.replay(mockRequest); EasyMock.replay(mockResponse); diff --git a/jibu-web/jibu-core-extjs/src/test/java/org/gaixie/jibu/security/servlet/MainServletTest.java b/jibu-web/jibu-core-extjs/src/test/java/org/gaixie/jibu/security/servlet/MainServletTest.java index f47b8a1..f92d8d0 100644 --- a/jibu-web/jibu-core-extjs/src/test/java/org/gaixie/jibu/security/servlet/MainServletTest.java +++ b/jibu-web/jibu-core-extjs/src/test/java/org/gaixie/jibu/security/servlet/MainServletTest.java @@ -62,8 +62,8 @@ public class MainServletTest { Map map = new TreeMap(); map.put("system","#"); map.put("system.administration","#"); - map.put("system.administration.pm","/PMServlet.z"); - map.put("system.setting","/SettingServet.y"); + map.put("system.administration.pm","/Role.z"); + map.put("system.setting","/Setting.y"); EasyMock.expect(mockAuthService.findMapByUsername("admin")).andReturn(map); EasyMock.replay(mockRequest); -- 2.11.4.GIT