系统已经做好,现在想设计一个登录,求给些思路:
例如csdn我已经登录,我再新建一个网页,输入csdn网址,我的状态就是已登录,请问这个是怎么实现;
我现在需要通过这个功能设计到用户在系统里面复制了超链接到execl表里面,直接点击也可以通过上面的判断进入系统。
例如csdn我已经登录,我再新建一个网页,输入csdn网址,我的状态就是已登录,请问这个是怎么实现;
我现在需要通过这个功能设计到用户在系统里面复制了超链接到execl表里面,直接点击也可以通过上面的判断进入系统。
调试欢乐多
判断用户是否为登录状态 以及权限
http://blog.csdn.net/shadowsick/article/details/8903278
可以参考下我博客里的项目实例,相信对你有比较大的帮助,谢谢支持
我发现就是不同所以没思路,比如我直接在网页输入网址可以调用cookie,但是从excel超链接的时候就没调用cookie,所以我很茫然,,,
* 获取当前登入用户的信息
*/
private void getLoginUser(HttpServletRequest req, HttpServletResponse res)
throws Exception {
Cookie[] cookies = req.getCookies();
String value = null;
HttpClient client = new HttpClient(); client.getHostConfiguration().setHost(this.getOaHost(),
this.getOaPort(), this.getOaPotal());
GetMethod get = new GetMethod(this.getOaPage() + "?" + Math.random()); // 加随机参数,防止请求缓存 String mySessionId = req.getSession().getId(); if (cookies != null) {
for (int i = 0; i < cookies.length; i++) {
String name = cookies[i].getName();
value = cookies[i].getValue();
if (name.equals("JSESSIONID") && !value.equals(mySessionId)) {// 说明这个value就是刚才登录OA时获得的JSESSIONID
System.out.println("发给OA的:" + value);
client.getState().addCookie(
new org.apache.commons.httpclient.Cookie(this
.getOaHost(), "JSESSIONID", value, "/", -1,
false));
}
}
} client.executeMethod(get);
String bodyStr = get.getResponseBodyAsString();
if (bodyStr == null || bodyStr.length() == 0) {
return;
}
int index1 = bodyStr.indexOf("<username>");
int index2 = bodyStr.indexOf("</username>");
if (index1 == -1 || index2 == -1) {
return;
}
String userFullName = bodyStr.substring(index1 + 10, index2); UserInfo2 ui = userService.getUserinfo2(userFullName); if (ui == null) {
return;
} // 初始化当前用户的角色信息列表
if (ui != null) {
long userId = ui.getUserId();
String userName = ui.getFullName();
AuthenticationProvider provider = new AuthenticationProvider(
userId, userName, this.getUserDetailsManager());
provider.doAuthentication();
CurrentUser cu = new CurrentUser();
cu.setUserId(userId);
cu.setDivision(ui.getDivision());
cu.setFullName(ui.getFullName());
cu.setOadepartFullNameCN(ui.getDepartName());
cu.setWorkNumber((Long) ui.getWorkNum() == null ? null : Integer
.parseInt(ui.getWorkNum() + ""));// 注意:oainterface1.2.3.jar提供了用户信息
cu.setShortNameCn(ui.getShortNameCn());
// 添加当前登录用户信息
HttpSession session = req.getSession();
session.setAttribute("cu", cu);
} }
我发现就是不同所以没思路,比如我直接在网页输入网址可以调用cookie,但是从excel超链接的时候就没调用cookie,所以我很茫然,,,刚用session实际测试了下,cookie应该也是一样的做法, 页面test1 里面session.setAttribute("usertest", "test"); 页面2里面session.getAttribute("usertest"); 然后做判断,打印出session的值,不匹配就跳转errorpage,在页面打印出来, 然后新建个excel, 复制页面2地址 粘贴上去,从excel表中点击超链接访问页面2,发现一切正常,测试的浏览器是ie 和360,office2007。 没有问题。你也可以设计简单的3个页面这么排查一下,或者去另一台机子排查一下。
我发现就是不同所以没思路,比如我直接在网页输入网址可以调用cookie,但是从excel超链接的时候就没调用cookie,所以我很茫然,,,刚用session实际测试了下,cookie应该也是一样的做法, 页面test1 里面session.setAttribute("usertest", "test"); 页面2里面session.getAttribute("usertest"); 然后做判断,打印出session的值,不匹配就跳转errorpage,在页面打印出来, 然后新建个excel, 复制页面2地址 粘贴上去,从excel表中点击超链接访问页面2,发现一切正常,测试的浏览器是ie 和360,office2007。 没有问题。你也可以设计简单的3个页面这么排查一下,或者去另一台机子排查一下。谢谢了,因为client.executeMethod(get);这里还需要获取用户信息判断,但是client.executeMethod(get);却绑定不了另外一台服务器,所以一直出错,,,