HttpServletResponse resp, String destination)
throws ServletException, IOException {
FileOutputStream byteout = null;
DataInputStream inputStream = null;
try {
String contentType =Facility.procNull(req.getParameter("contentType"));
String currUser = (String) req.getSession()
.getAttribute("userName");
String businessId = Facility.procNull(req.getParameter("businessId"));
String workitem_id = Facility.procNull(req.getParameter("workitem_id"));
workitem_id = URLDecoder.decode(workitem_id,"utf-8");
inputStream = new DataInputStream(req.getInputStream());
int filesize = inputStream.available();
// 创建附件对象
String attId = IDCreateFactory.getIDByName(Document.IDNAME);
String fileName = "content" + System.currentTimeMillis()
+ contentType;
String app_filename = attId
+ fileName.substring(fileName.lastIndexOf("."));
Document document = new Document(attId, currUser, fileName,
app_filename, filesize, destination, null, null, null);
// 创建附件信息对象
String bAttId = IDCreateFactory.getIDByName(Content.IDNAME);
Content content = new Content(bAttId, businessId, currUser,
new Date(), workitem_id, currUser, new Date(), 1, 0, attId);
contentService.saveContentAndDocument(content, document);
// 保存正文文件
System.out.println("1-->" + root + destination);
File saveFile = new File(root + destination + app_filename);
byteout = new FileOutputStream(saveFile);
int c = 0;
byte[] bytes = new byte[1024];
while ((c = inputStream.read(bytes)) != -1) {
byteout.write(bytes, 0, c);
}
// 日志开始
String action = this.getClass().getName()
+ "uploadOnCreate(HttpServletRequest req,HttpServletResponse resp, String destination)";
String logDescription = "新建Id:【"+bAttId+"】名称:【" +fileName + "】正文";
UserOperationLog userOperationLog = new UserOperationLog(action,
UserOperationLog.TYPE_USEROPERATE, UserOperationLog.PROTO_INSERT,
logDescription);
this.saveUserOperationLog(req, userOperationLog);
// 日志结束
} catch (Exception e) {
e.printStackTrace();
} finally {
byteout.flush();
byteout.close();
inputStream.close();
}
}
哪位大神帮忙看一下
24 个解决方案
#1
你session是怎么存的, 还有确保你session没被清除
#2
//代码
贴代码注意一下格式,看的脑袋疼没看到在哪里放的,在哪取的
#3
你最好把上一个处理数据的页面或者servlet也发出来看看
#4
不好意思哈,第一次在这上面发帖求助,没太注意,这个就是servlet
#5
//创建session
public void createdSession(HttpServletRequest request) {
HttpSession session=request.getSession();
if(session!=null)
{
String sessionId=session.getId();
String loginName=(String)session.getAttribute("loginname");
String userName=new SXRecipient((String)session.getAttribute(IUser.USER_ID)).getRecipName();
String userIp=(String)session.getAttribute("iv-remote-address");
String departmentName="";
Vector v=(Vector)request.getSession().getAttribute(IUser.USER_ORG_ID_NAME);
if(v!=null)
{
departmentName=new SXRecipient(v.get(0)).getRecipName();
}
OnlineUser user=new OnlineUser();
user.setLoginName(loginName);
user.setUserIp(userIp);
user.setLoginTime(new Date());
user.setUserName(userName);
user.setDepartmentName(departmentName);
online.put(loginName, user);
}
}
这个是存值的代码
public void createdSession(HttpServletRequest request) {
HttpSession session=request.getSession();
if(session!=null)
{
String sessionId=session.getId();
String loginName=(String)session.getAttribute("loginname");
String userName=new SXRecipient((String)session.getAttribute(IUser.USER_ID)).getRecipName();
String userIp=(String)session.getAttribute("iv-remote-address");
String departmentName="";
Vector v=(Vector)request.getSession().getAttribute(IUser.USER_ORG_ID_NAME);
if(v!=null)
{
departmentName=new SXRecipient(v.get(0)).getRecipName();
}
OnlineUser user=new OnlineUser();
user.setLoginName(loginName);
user.setUserIp(userIp);
user.setLoginTime(new Date());
user.setUserName(userName);
user.setDepartmentName(departmentName);
online.put(loginName, user);
}
}
这个是存值的代码
#6
package com.business.login;
import java.util.Date;
import java.util.HashMap;
import java.util.Vector;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;
import com.business.workflow.SXRecipient;
import com.dhcc.framework.core.IUser;
/**
* session监听
* @author yuelulu
*
*/
public class OnlineCounterListener implements HttpSessionListener {
public static HashMap<String,OnlineUser> online=new HashMap<String,OnlineUser>();
public void sessionCreated(HttpSessionEvent event) {
//raise();
}
//销毁session
public void sessionDestroyed(HttpSessionEvent event) {
HttpSession session=event.getSession();
String sessionId=session.getId();
String loginName=(String)session.getAttribute("loginname");
online.remove(loginName);
}
//创建session
public void createdSession(HttpServletRequest request) {
HttpSession session=request.getSession();
if(session!=null)
{
String sessionId=session.getId();
String loginName=(String)session.getAttribute("loginname");
String userName=new SXRecipient((String)session.getAttribute(IUser.USER_ID)).getRecipName();
String userIp=(String)session.getAttribute("iv-remote-address");
String departmentName="";
Vector v=(Vector)request.getSession().getAttribute(IUser.USER_ORG_ID_NAME);
if(v!=null)
{
departmentName=new SXRecipient(v.get(0)).getRecipName();
}
OnlineUser user=new OnlineUser();
user.setLoginName(loginName);
user.setUserIp(userIp);
user.setLoginTime(new Date());
user.setUserName(userName);
user.setDepartmentName(departmentName);
online.put(loginName, user);
}
}
public static int getOnline() {
return online.size();
}
}
import java.util.Date;
import java.util.HashMap;
import java.util.Vector;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;
import com.business.workflow.SXRecipient;
import com.dhcc.framework.core.IUser;
/**
* session监听
* @author yuelulu
*
*/
public class OnlineCounterListener implements HttpSessionListener {
public static HashMap<String,OnlineUser> online=new HashMap<String,OnlineUser>();
public void sessionCreated(HttpSessionEvent event) {
//raise();
}
//销毁session
public void sessionDestroyed(HttpSessionEvent event) {
HttpSession session=event.getSession();
String sessionId=session.getId();
String loginName=(String)session.getAttribute("loginname");
online.remove(loginName);
}
//创建session
public void createdSession(HttpServletRequest request) {
HttpSession session=request.getSession();
if(session!=null)
{
String sessionId=session.getId();
String loginName=(String)session.getAttribute("loginname");
String userName=new SXRecipient((String)session.getAttribute(IUser.USER_ID)).getRecipName();
String userIp=(String)session.getAttribute("iv-remote-address");
String departmentName="";
Vector v=(Vector)request.getSession().getAttribute(IUser.USER_ORG_ID_NAME);
if(v!=null)
{
departmentName=new SXRecipient(v.get(0)).getRecipName();
}
OnlineUser user=new OnlineUser();
user.setLoginName(loginName);
user.setUserIp(userIp);
user.setLoginTime(new Date());
user.setUserName(userName);
user.setDepartmentName(departmentName);
online.put(loginName, user);
}
}
public static int getOnline() {
return online.size();
}
}
#7
我看你的代码里面 就没有session.setAttribute("userName","你的userName");
你能取到userName的值才见鬼了
你能取到userName的值才见鬼了
#8
之前username已经存到session里了,直接从session里取不行吗
#9
//这句只是拿到userName,但session并没有存起来
String userName=new SXRecipient((String)session.getAttribute(IUser.USER_ID)).getRecipName();
//这样才存起来
session.setAttribute("userName",userName);
#10
不要用(String)这种强制类型装换 用toString方法试试
#11
哦哦,这样啊,谢谢答复!
#12
这个应该不是大问题吧,因为别的数据这样写也可以取到啊
#13
好像是没有存到session
#14
username你没有存到session里面,session.setAttribute("username",username);这才可以取值
#15
每次看到你这个头像都觉得很魔性....
#16
package com.business.filter;
import java.io.IOException;
import java.util.Date;
import java.util.Hashtable;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.business.login.Login;
import com.business.login.OnlineCounterListener;
import com.business.workflow.SXRecipient;
import com.dhcc.framework.core.IUser;
import com.dhcc.framework.log.po.UserOperationLog;
import com.dhcc.framework.log.service.UserOperationLogService;
import com.dhcc.framework.util.Facility;
public class LoginFilter implements Filter {
public void destroy() {
}
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
HttpServletRequest req = (HttpServletRequest)request;
HttpServletResponse res = (HttpServletResponse)response;
String username = "";
String userIp="";
username = Facility.procNull((String)req.getSession().getAttribute("iv-user"));
userIp = Facility.procNull((String)req.getSession().getAttribute("iv-remote-address"));
String gotoUrl = req.getRequestURI();
if("".equals(username)){
username = Facility.procNull(req.getHeader("iv-user"));
userIp = Facility.procNull(req.getHeader("iv-remote-address"));
if(noFilter(gotoUrl)){
if("".equals(username)){
String oaLogoutPage ="http://" + req.getServerName()+":"+req.getServerPort()+req.getContextPath()+"/loginout.jsp";
res.sendRedirect(oaLogoutPage);
return;
}else{
Hashtable ht=null;
try {
ht = Login.getV(username);
req.getSession().setAttribute(IUser.USER_LOGINNAME,username);
req.getSession().setAttribute(IUser.USER_ID, ht.get(IUser.USER_ID));
req.getSession().setAttribute(IUser.USER_POSITION_ID_NAME, ht.get(IUser.USER_POSITION_ID_NAME));
req.getSession().setAttribute(IUser.USER_ORG_ID_NAME, ht.get(IUser.USER_ORG_ID_NAME));
req.getSession().setAttribute(IUser.USER_JOB, ht.get(IUser.USER_JOB));
req.getSession().setAttribute(IUser.USER_MANAGER, ht.get(IUser.USER_MANAGER));
req.getSession().setAttribute(IUser.USER_SYSRIGHT, ht.get(IUser.USER_SYSRIGHT));
req.getSession().setAttribute(IUser.USER_SECRETLEVEL, ht.get(IUser.USER_SECRETLEVEL));
req.getSession().setAttribute(IUser.USER_BASEINFOLIST, ht.get(IUser.USER_BASEINFOLIST));
req.getSession().setAttribute("iv-user",username);
req.getSession().setAttribute("iv-remote-address",userIp);
new OnlineCounterListener().createdSession(req);
//登录日志开始------------------>
UserOperationLogService userOperationLogService = UserOperationLogService.getInstance();
SXRecipient recipt = new SXRecipient(ht.get(IUser.USER_ID));
String opdescription = "用户登录:"+recipt.getRecipientName()+"|"+username+"(登录名)";//描述
UserOperationLog useroperationlog=new UserOperationLog("", recipt.getRecipId(), userIp, opdescription, new Date(), "login.jsp", UserOperationLog.TYPE_USERLOGIN,"no");
useroperationlog.setProtoOperation(UserOperationLog.PROTO_QUERY);
userOperationLogService.saveUserOperationLog(useroperationlog);
//登录日志结束------------------>
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
req.setCharacterEncoding("GBK");
res.setCharacterEncoding("GBK");
res.setContentType("text/html;charset=GBK");
chain.doFilter(request, response);
return;
}
public void init(FilterConfig arg0) throws ServletException {
}
public boolean noFilter(String gotoUrl)//不拦截哪个页面写在下面
{
boolean filter=(gotoUrl.endsWith("html") || gotoUrl.endsWith("htm") || gotoUrl.endsWith("jsp") || (gotoUrl.indexOf("/mcc")>-1) )
&& !gotoUrl.endsWith("index.htm")
&& !gotoUrl.endsWith("login.html")
&& !gotoUrl.endsWith("login/login.jsp")
&& !gotoUrl.endsWith("loginout.jsp");
return filter;
}
}
各位,这个已经把session放值了啊
import java.io.IOException;
import java.util.Date;
import java.util.Hashtable;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.business.login.Login;
import com.business.login.OnlineCounterListener;
import com.business.workflow.SXRecipient;
import com.dhcc.framework.core.IUser;
import com.dhcc.framework.log.po.UserOperationLog;
import com.dhcc.framework.log.service.UserOperationLogService;
import com.dhcc.framework.util.Facility;
public class LoginFilter implements Filter {
public void destroy() {
}
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
HttpServletRequest req = (HttpServletRequest)request;
HttpServletResponse res = (HttpServletResponse)response;
String username = "";
String userIp="";
username = Facility.procNull((String)req.getSession().getAttribute("iv-user"));
userIp = Facility.procNull((String)req.getSession().getAttribute("iv-remote-address"));
String gotoUrl = req.getRequestURI();
if("".equals(username)){
username = Facility.procNull(req.getHeader("iv-user"));
userIp = Facility.procNull(req.getHeader("iv-remote-address"));
if(noFilter(gotoUrl)){
if("".equals(username)){
String oaLogoutPage ="http://" + req.getServerName()+":"+req.getServerPort()+req.getContextPath()+"/loginout.jsp";
res.sendRedirect(oaLogoutPage);
return;
}else{
Hashtable ht=null;
try {
ht = Login.getV(username);
req.getSession().setAttribute(IUser.USER_LOGINNAME,username);
req.getSession().setAttribute(IUser.USER_ID, ht.get(IUser.USER_ID));
req.getSession().setAttribute(IUser.USER_POSITION_ID_NAME, ht.get(IUser.USER_POSITION_ID_NAME));
req.getSession().setAttribute(IUser.USER_ORG_ID_NAME, ht.get(IUser.USER_ORG_ID_NAME));
req.getSession().setAttribute(IUser.USER_JOB, ht.get(IUser.USER_JOB));
req.getSession().setAttribute(IUser.USER_MANAGER, ht.get(IUser.USER_MANAGER));
req.getSession().setAttribute(IUser.USER_SYSRIGHT, ht.get(IUser.USER_SYSRIGHT));
req.getSession().setAttribute(IUser.USER_SECRETLEVEL, ht.get(IUser.USER_SECRETLEVEL));
req.getSession().setAttribute(IUser.USER_BASEINFOLIST, ht.get(IUser.USER_BASEINFOLIST));
req.getSession().setAttribute("iv-user",username);
req.getSession().setAttribute("iv-remote-address",userIp);
new OnlineCounterListener().createdSession(req);
//登录日志开始------------------>
UserOperationLogService userOperationLogService = UserOperationLogService.getInstance();
SXRecipient recipt = new SXRecipient(ht.get(IUser.USER_ID));
String opdescription = "用户登录:"+recipt.getRecipientName()+"|"+username+"(登录名)";//描述
UserOperationLog useroperationlog=new UserOperationLog("", recipt.getRecipId(), userIp, opdescription, new Date(), "login.jsp", UserOperationLog.TYPE_USERLOGIN,"no");
useroperationlog.setProtoOperation(UserOperationLog.PROTO_QUERY);
userOperationLogService.saveUserOperationLog(useroperationlog);
//登录日志结束------------------>
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
req.setCharacterEncoding("GBK");
res.setCharacterEncoding("GBK");
res.setContentType("text/html;charset=GBK");
chain.doFilter(request, response);
return;
}
public void init(FilterConfig arg0) throws ServletException {
}
public boolean noFilter(String gotoUrl)//不拦截哪个页面写在下面
{
boolean filter=(gotoUrl.endsWith("html") || gotoUrl.endsWith("htm") || gotoUrl.endsWith("jsp") || (gotoUrl.indexOf("/mcc")>-1) )
&& !gotoUrl.endsWith("index.htm")
&& !gotoUrl.endsWith("login.html")
&& !gotoUrl.endsWith("login/login.jsp")
&& !gotoUrl.endsWith("loginout.jsp");
return filter;
}
}
各位,这个已经把session放值了啊
#17
print(null==session.getAttribute("userName")),true就是没有传入,传入代码有问题,false就是有获取,断点看看里面内容
#18
楼猪,乖,听话
#19
结果就是没有存进session?
#20
程序媛发帖回复率就是不一样
#21
每次我都能吓尿
#22
哈哈,宝宝乖着呢
#23
结果就是没有存进session?
结果是转码的问题
#24
程序媛发帖回复率就是不一样
哈哈,羡慕嫉妒恨吧,以后你发帖也可以伪程序媛
#1
你session是怎么存的, 还有确保你session没被清除
#2
//代码
贴代码注意一下格式,看的脑袋疼没看到在哪里放的,在哪取的
#3
你最好把上一个处理数据的页面或者servlet也发出来看看
#4
不好意思哈,第一次在这上面发帖求助,没太注意,这个就是servlet
#5
//创建session
public void createdSession(HttpServletRequest request) {
HttpSession session=request.getSession();
if(session!=null)
{
String sessionId=session.getId();
String loginName=(String)session.getAttribute("loginname");
String userName=new SXRecipient((String)session.getAttribute(IUser.USER_ID)).getRecipName();
String userIp=(String)session.getAttribute("iv-remote-address");
String departmentName="";
Vector v=(Vector)request.getSession().getAttribute(IUser.USER_ORG_ID_NAME);
if(v!=null)
{
departmentName=new SXRecipient(v.get(0)).getRecipName();
}
OnlineUser user=new OnlineUser();
user.setLoginName(loginName);
user.setUserIp(userIp);
user.setLoginTime(new Date());
user.setUserName(userName);
user.setDepartmentName(departmentName);
online.put(loginName, user);
}
}
这个是存值的代码
public void createdSession(HttpServletRequest request) {
HttpSession session=request.getSession();
if(session!=null)
{
String sessionId=session.getId();
String loginName=(String)session.getAttribute("loginname");
String userName=new SXRecipient((String)session.getAttribute(IUser.USER_ID)).getRecipName();
String userIp=(String)session.getAttribute("iv-remote-address");
String departmentName="";
Vector v=(Vector)request.getSession().getAttribute(IUser.USER_ORG_ID_NAME);
if(v!=null)
{
departmentName=new SXRecipient(v.get(0)).getRecipName();
}
OnlineUser user=new OnlineUser();
user.setLoginName(loginName);
user.setUserIp(userIp);
user.setLoginTime(new Date());
user.setUserName(userName);
user.setDepartmentName(departmentName);
online.put(loginName, user);
}
}
这个是存值的代码
#6
package com.business.login;
import java.util.Date;
import java.util.HashMap;
import java.util.Vector;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;
import com.business.workflow.SXRecipient;
import com.dhcc.framework.core.IUser;
/**
* session监听
* @author yuelulu
*
*/
public class OnlineCounterListener implements HttpSessionListener {
public static HashMap<String,OnlineUser> online=new HashMap<String,OnlineUser>();
public void sessionCreated(HttpSessionEvent event) {
//raise();
}
//销毁session
public void sessionDestroyed(HttpSessionEvent event) {
HttpSession session=event.getSession();
String sessionId=session.getId();
String loginName=(String)session.getAttribute("loginname");
online.remove(loginName);
}
//创建session
public void createdSession(HttpServletRequest request) {
HttpSession session=request.getSession();
if(session!=null)
{
String sessionId=session.getId();
String loginName=(String)session.getAttribute("loginname");
String userName=new SXRecipient((String)session.getAttribute(IUser.USER_ID)).getRecipName();
String userIp=(String)session.getAttribute("iv-remote-address");
String departmentName="";
Vector v=(Vector)request.getSession().getAttribute(IUser.USER_ORG_ID_NAME);
if(v!=null)
{
departmentName=new SXRecipient(v.get(0)).getRecipName();
}
OnlineUser user=new OnlineUser();
user.setLoginName(loginName);
user.setUserIp(userIp);
user.setLoginTime(new Date());
user.setUserName(userName);
user.setDepartmentName(departmentName);
online.put(loginName, user);
}
}
public static int getOnline() {
return online.size();
}
}
import java.util.Date;
import java.util.HashMap;
import java.util.Vector;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;
import com.business.workflow.SXRecipient;
import com.dhcc.framework.core.IUser;
/**
* session监听
* @author yuelulu
*
*/
public class OnlineCounterListener implements HttpSessionListener {
public static HashMap<String,OnlineUser> online=new HashMap<String,OnlineUser>();
public void sessionCreated(HttpSessionEvent event) {
//raise();
}
//销毁session
public void sessionDestroyed(HttpSessionEvent event) {
HttpSession session=event.getSession();
String sessionId=session.getId();
String loginName=(String)session.getAttribute("loginname");
online.remove(loginName);
}
//创建session
public void createdSession(HttpServletRequest request) {
HttpSession session=request.getSession();
if(session!=null)
{
String sessionId=session.getId();
String loginName=(String)session.getAttribute("loginname");
String userName=new SXRecipient((String)session.getAttribute(IUser.USER_ID)).getRecipName();
String userIp=(String)session.getAttribute("iv-remote-address");
String departmentName="";
Vector v=(Vector)request.getSession().getAttribute(IUser.USER_ORG_ID_NAME);
if(v!=null)
{
departmentName=new SXRecipient(v.get(0)).getRecipName();
}
OnlineUser user=new OnlineUser();
user.setLoginName(loginName);
user.setUserIp(userIp);
user.setLoginTime(new Date());
user.setUserName(userName);
user.setDepartmentName(departmentName);
online.put(loginName, user);
}
}
public static int getOnline() {
return online.size();
}
}
#7
我看你的代码里面 就没有session.setAttribute("userName","你的userName");
你能取到userName的值才见鬼了
你能取到userName的值才见鬼了
#8
之前username已经存到session里了,直接从session里取不行吗
#9
//这句只是拿到userName,但session并没有存起来
String userName=new SXRecipient((String)session.getAttribute(IUser.USER_ID)).getRecipName();
//这样才存起来
session.setAttribute("userName",userName);
#10
不要用(String)这种强制类型装换 用toString方法试试
#11
//这句只是拿到userName,但session并没有存起来
String userName=new SXRecipient((String)session.getAttribute(IUser.USER_ID)).getRecipName();
//这样才存起来
session.setAttribute("userName",userName);
哦哦,这样啊,谢谢答复!
#12
不要用(String)这种强制类型装换 用toString方法试试
这个应该不是大问题吧,因为别的数据这样写也可以取到啊
#13
之前username已经存到session里了,直接从session里取不行吗
好像是没有存到session
#14
username你没有存到session里面,session.setAttribute("username",username);这才可以取值
#15
(String)session.getAttribute("userName")取值为空?
你session是怎么存的,还有确保你session没被清除
#16
package com.business.filter;
import java.io.IOException;
import java.util.Date;
import java.util.Hashtable;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.business.login.Login;
import com.business.login.OnlineCounterListener;
import com.business.workflow.SXRecipient;
import com.dhcc.framework.core.IUser;
import com.dhcc.framework.log.po.UserOperationLog;
import com.dhcc.framework.log.service.UserOperationLogService;
import com.dhcc.framework.util.Facility;
public class LoginFilter implements Filter {
public void destroy() {
}
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
HttpServletRequest req = (HttpServletRequest)request;
HttpServletResponse res = (HttpServletResponse)response;
String username = "";
String userIp="";
username = Facility.procNull((String)req.getSession().getAttribute("iv-user"));
userIp = Facility.procNull((String)req.getSession().getAttribute("iv-remote-address"));
String gotoUrl = req.getRequestURI();
if("".equals(username)){
username = Facility.procNull(req.getHeader("iv-user"));
userIp = Facility.procNull(req.getHeader("iv-remote-address"));
if(noFilter(gotoUrl)){
if("".equals(username)){
String oaLogoutPage ="http://" + req.getServerName()+":"+req.getServerPort()+req.getContextPath()+"/loginout.jsp";
res.sendRedirect(oaLogoutPage);
return;
}else{
Hashtable ht=null;
try {
ht = Login.getV(username);
req.getSession().setAttribute(IUser.USER_LOGINNAME,username);
req.getSession().setAttribute(IUser.USER_ID, ht.get(IUser.USER_ID));
req.getSession().setAttribute(IUser.USER_POSITION_ID_NAME, ht.get(IUser.USER_POSITION_ID_NAME));
req.getSession().setAttribute(IUser.USER_ORG_ID_NAME, ht.get(IUser.USER_ORG_ID_NAME));
req.getSession().setAttribute(IUser.USER_JOB, ht.get(IUser.USER_JOB));
req.getSession().setAttribute(IUser.USER_MANAGER, ht.get(IUser.USER_MANAGER));
req.getSession().setAttribute(IUser.USER_SYSRIGHT, ht.get(IUser.USER_SYSRIGHT));
req.getSession().setAttribute(IUser.USER_SECRETLEVEL, ht.get(IUser.USER_SECRETLEVEL));
req.getSession().setAttribute(IUser.USER_BASEINFOLIST, ht.get(IUser.USER_BASEINFOLIST));
req.getSession().setAttribute("iv-user",username);
req.getSession().setAttribute("iv-remote-address",userIp);
new OnlineCounterListener().createdSession(req);
//登录日志开始------------------>
UserOperationLogService userOperationLogService = UserOperationLogService.getInstance();
SXRecipient recipt = new SXRecipient(ht.get(IUser.USER_ID));
String opdescription = "用户登录:"+recipt.getRecipientName()+"|"+username+"(登录名)";//描述
UserOperationLog useroperationlog=new UserOperationLog("", recipt.getRecipId(), userIp, opdescription, new Date(), "login.jsp", UserOperationLog.TYPE_USERLOGIN,"no");
useroperationlog.setProtoOperation(UserOperationLog.PROTO_QUERY);
userOperationLogService.saveUserOperationLog(useroperationlog);
//登录日志结束------------------>
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
req.setCharacterEncoding("GBK");
res.setCharacterEncoding("GBK");
res.setContentType("text/html;charset=GBK");
chain.doFilter(request, response);
return;
}
public void init(FilterConfig arg0) throws ServletException {
}
public boolean noFilter(String gotoUrl)//不拦截哪个页面写在下面
{
boolean filter=(gotoUrl.endsWith("html") || gotoUrl.endsWith("htm") || gotoUrl.endsWith("jsp") || (gotoUrl.indexOf("/mcc")>-1) )
&& !gotoUrl.endsWith("index.htm")
&& !gotoUrl.endsWith("login.html")
&& !gotoUrl.endsWith("login/login.jsp")
&& !gotoUrl.endsWith("loginout.jsp");
return filter;
}
}
各位,这个已经把session放值了啊
import java.io.IOException;
import java.util.Date;
import java.util.Hashtable;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.business.login.Login;
import com.business.login.OnlineCounterListener;
import com.business.workflow.SXRecipient;
import com.dhcc.framework.core.IUser;
import com.dhcc.framework.log.po.UserOperationLog;
import com.dhcc.framework.log.service.UserOperationLogService;
import com.dhcc.framework.util.Facility;
public class LoginFilter implements Filter {
public void destroy() {
}
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
HttpServletRequest req = (HttpServletRequest)request;
HttpServletResponse res = (HttpServletResponse)response;
String username = "";
String userIp="";
username = Facility.procNull((String)req.getSession().getAttribute("iv-user"));
userIp = Facility.procNull((String)req.getSession().getAttribute("iv-remote-address"));
String gotoUrl = req.getRequestURI();
if("".equals(username)){
username = Facility.procNull(req.getHeader("iv-user"));
userIp = Facility.procNull(req.getHeader("iv-remote-address"));
if(noFilter(gotoUrl)){
if("".equals(username)){
String oaLogoutPage ="http://" + req.getServerName()+":"+req.getServerPort()+req.getContextPath()+"/loginout.jsp";
res.sendRedirect(oaLogoutPage);
return;
}else{
Hashtable ht=null;
try {
ht = Login.getV(username);
req.getSession().setAttribute(IUser.USER_LOGINNAME,username);
req.getSession().setAttribute(IUser.USER_ID, ht.get(IUser.USER_ID));
req.getSession().setAttribute(IUser.USER_POSITION_ID_NAME, ht.get(IUser.USER_POSITION_ID_NAME));
req.getSession().setAttribute(IUser.USER_ORG_ID_NAME, ht.get(IUser.USER_ORG_ID_NAME));
req.getSession().setAttribute(IUser.USER_JOB, ht.get(IUser.USER_JOB));
req.getSession().setAttribute(IUser.USER_MANAGER, ht.get(IUser.USER_MANAGER));
req.getSession().setAttribute(IUser.USER_SYSRIGHT, ht.get(IUser.USER_SYSRIGHT));
req.getSession().setAttribute(IUser.USER_SECRETLEVEL, ht.get(IUser.USER_SECRETLEVEL));
req.getSession().setAttribute(IUser.USER_BASEINFOLIST, ht.get(IUser.USER_BASEINFOLIST));
req.getSession().setAttribute("iv-user",username);
req.getSession().setAttribute("iv-remote-address",userIp);
new OnlineCounterListener().createdSession(req);
//登录日志开始------------------>
UserOperationLogService userOperationLogService = UserOperationLogService.getInstance();
SXRecipient recipt = new SXRecipient(ht.get(IUser.USER_ID));
String opdescription = "用户登录:"+recipt.getRecipientName()+"|"+username+"(登录名)";//描述
UserOperationLog useroperationlog=new UserOperationLog("", recipt.getRecipId(), userIp, opdescription, new Date(), "login.jsp", UserOperationLog.TYPE_USERLOGIN,"no");
useroperationlog.setProtoOperation(UserOperationLog.PROTO_QUERY);
userOperationLogService.saveUserOperationLog(useroperationlog);
//登录日志结束------------------>
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
req.setCharacterEncoding("GBK");
res.setCharacterEncoding("GBK");
res.setContentType("text/html;charset=GBK");
chain.doFilter(request, response);
return;
}
public void init(FilterConfig arg0) throws ServletException {
}
public boolean noFilter(String gotoUrl)//不拦截哪个页面写在下面
{
boolean filter=(gotoUrl.endsWith("html") || gotoUrl.endsWith("htm") || gotoUrl.endsWith("jsp") || (gotoUrl.indexOf("/mcc")>-1) )
&& !gotoUrl.endsWith("index.htm")
&& !gotoUrl.endsWith("login.html")
&& !gotoUrl.endsWith("login/login.jsp")
&& !gotoUrl.endsWith("loginout.jsp");
return filter;
}
}
各位,这个已经把session放值了啊
#17
print(null==session.getAttribute("userName")),true就是没有传入,传入代码有问题,false就是有获取,断点看看里面内容
#18
//代码
贴代码注意一下格式,看的脑袋疼没看到在哪里放的,在哪取的
楼猪,乖,听话
#19
结果就是没有存进session?
#20
程序媛发帖回复率就是不一样
#21
username你没有存到session里面,session.setAttribute("username",username);这才可以取值
#22
//代码
贴代码注意一下格式,看的脑袋疼没看到在哪里放的,在哪取的
楼猪,乖,听话
哈哈,宝宝乖着呢
#23
结果就是没有存进session?
结果是转码的问题
#24
程序媛发帖回复率就是不一样
哈哈,羡慕嫉妒恨吧,以后你发帖也可以伪程序媛