域名访问项目session为空

JavaWeb项目一开始本地访问,session可以取到值,没有问题。
添加到服务器后,使用的是IP访问,session也可以取值。
最近申请了域名,域名绑定了项目访问的地址,输入域名,可以正常跳转到主界面,
在主界面上传一个文件,显示界面无法获取,session的值为空?
怎么才能正常获取到session中的值?
求解!!!

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
session为何为空?
<%rn name = rtrim(ltrim(request.form("userlogin")))rn pass = rtrim(ltrim(request.form("password")))rnrn if request("submit") = "确定" then rn sql="select * from manager where name='"& name&"'"rn rs.open sql,con,1,1rn if name<> "" thenrn if rs.recordcount=0 then rn response.write " 请先注册" rn elseif rs.recordcount>0 and pass<>rs("pass") thenrn response.write " 密码有误" rn else rn session("user") = userrn response.redirect("index.asp")rn end ifrn elsern session("user") = ""rn response.redirect("index.asp")rn end ifrn end ifrn%>rn发现无论name 是什么 session("user") 都是空的,
session为空的问题
请问如何判断session里没有对象啊,就像打印出来是这样的结果[]一样啊,请大侠们解答
session取值为空
[color=#003366]登录成功 ,登录数据已经存入session ,经验证取证正常。但是向数据库添加数据的过程中 session取值竟然为空。费解!![/color]rnrnrnrn[color=#800000]1.登录servlet 登录成功并转向,session成功写入。[/color]rn[code=Java]rnpackage ser;rnrnimport impl.AccountImpl;rnimport it.shopping.dao.IAccount;rnimport it.shopping.pojo.Account;rnrnimport java.io.IOException;rnimport javax.servlet.ServletException;rnimport javax.servlet.http.HttpServlet;rnimport javax.servlet.http.HttpServletRequest;rnimport javax.servlet.http.HttpServletResponse;rnrnpublic class AccountSer extends HttpServletrnrn rn rn private IAccount accountImpl = new AccountImpl();rn rn private static final long serialVersionUID = -3708568559174453120L;rn rn public AccountSer()rn rn super();rn rn rn public void destroy()rn rn super.destroy(); // Just puts "destroy" string in logrn // Put your code herern rnrn rn public void doGet(HttpServletRequest request, HttpServletResponse response)rn throws ServletException, IOExceptionrn rnrn this.doPost(request, response);rn rnrn rn public void doPost(HttpServletRequest request, HttpServletResponse response)rn throws ServletException, IOExceptionrn rn rn String status = request.getParameter("status");rn if(status.equals("login"))rn rn rn Account account = new Account();rn account.setAlogin(request.getParameter("alogin"));rn account.setApass(request.getParameter("apass"));rn account =accountImpl.queryAccount(account);rn rnrn rn if(account == null)rn rn request.setAttribute("error", "登录失败");rn request.getRequestDispatcher("/alogin.jsp").forward(request, response);rn // response.sendRedirect("alogin.jsp");rn rn rn rn rn request.getSession().setAttribute("account", account);rn // response.sendRedirect("/t31/admin/index.jsp");rn // 重定向和请求装啊session值都不会失效!rn request.getRequestDispatcher("/admin/index.jsp").forward(request, response);rn rn rn rn rn rn rn rnrn rn public void init() throws ServletExceptionrn rn // Put your code herern rn rnrnrnrn[/code]rnrn2.跳转至index.jsp成功,然后添加数据成功,跳转至servlet 即CategorySer.java成功rn但是在category.setAccount((Account) req.getSession().getAttribute("account"));rnsession 取值竟然为空!!求解释!!rn[code=Java]rnpackage ser;rnrnrnrnimport impl.CategoryImpl;rnimport it.shopping.dao.ICategory;rnimport it.shopping.pojo.Account;rnimport it.shopping.pojo.Category;rnrnimport java.io.IOException;rnrnrnimport javax.servlet.ServletException;rnimport javax.servlet.http.HttpServlet;rnimport javax.servlet.http.HttpServletRequest;rnimport javax.servlet.http.HttpServletResponse;rnrnrnrnpublic class CategorySer extends HttpServletrnrnrn rn private ICategory categoryImpl = new CategoryImpl();rn rn public void destroy() rn rn rn super.destroy();rn rn rnrn@Overridernprotected void doGet(HttpServletRequest req, HttpServletResponse resp)rn throws ServletException, IOExceptionrnrn this.doPost(req,resp);rnrnrn@Overridern protected void doPost(HttpServletRequest req, HttpServletResponse resp)rn throws ServletException, IOExceptionrn rn rn String status = req.getParameter("status");rn rn rn if(status.equals("savaCategory"));rn rn rn Category category = new Category();rn category.setCtype(req.getParameter("ctype"));rn rn category.setChot(Boolean.parseBoolean(req.getParameter("chot")));rn category.setAccount((Account) req.getSession().getAttribute("account"));rn rn System.out.println(category.getAccount());rn categoryImpl.queryCategory(category);rn rn rn rn resp.sendRedirect("/t31/admin/main.jsp");rnrn rn rn rn rn rn rn rn rn rn public void init() throws ServletExceptionrn rn rn rn rnrn[/code]rnrnrnrnrn———————————————————————————————————————————————————————rnrnPS:accountrn[code=Java]rnpackage it.shopping.pojo;rnrnpublic class Accountrnrnrn private int aid;rn private String alogin;rn private String apass;rn public int getAid()rn rn return aid;rn rn public void setAid(int aid)rn rn this.aid = aid;rn rn public String getAlogin()rn rn return alogin;rn rn public void setAlogin(String alogin)rn rn this.alogin = alogin;rn rn public String getApass()rn rn return apass;rn rn public void setApass(String apass)rn rn this.apass = apass;rn rn rn rn rnrn[/code]rnrnCategory.javarnrn[code=Java]rnpackage it.shopping.pojo;rnrnpublic class Categoryrnrnrn private int cid; rn private String ctype;rn private Boolean chot;rn private Account account;rn public int getCid()rn rn return cid;rn rn public void setCid(int cid)rn rn this.cid = cid;rn rn public String getCtype()rn rn return ctype;rn rn public void setCtype(String ctype)rn rn this.ctype = ctype;rn rn public Boolean getChot()rn rn return chot;rn rn public void setChot(Boolean chot)rn rn this.chot = chot;rn rn public Account getAccount()rn rn return account;rn rn public void setAccount(Account account)rn rn this.account = account;rn rn rnrn[/code]rnrnCategoryImp.javarnrn[code=Java]rnpackage impl;rnrnimport java.sql.Connection;rnimport java.sql.PreparedStatement;rnimport java.sql.ResultSet;rnimport java.sql.SQLException;rnrnimport utils.JdbcUtils;rnrnimport it.shopping.dao.ICategory;rnimport it.shopping.pojo.Category;rnrnpublic class CategoryImpl implements ICategoryrnrnrnrn @Overridernpublic Category queryCategory(Category category) rn rn rn Connection conn = null;rn PreparedStatement pre = null;rn String sql =" INSERT INTO category ?,?,?";rn ResultSet rs = null;rn rn tryrn rn rn System.out.println("hello3.0");rn conn = JdbcUtils.getConnection();rn pre = conn.prepareStatement(sql);rn System.out.println("hello4.0");rn System.out.println(category.getAccount().getAid());rn pre.setInt(1,category.getAccount().getAid());rn rn pre.setString(2, category.getCtype());rn pre.setBoolean(3,category.getChot());rn System.out.println("hello6.0");rn pre.executeQuery();rn rn rn rn catch (SQLException e)rn rn // TODO Auto-generated catch blockrn e.printStackTrace();rn finallyrn rn rn JdbcUtils.free(rs, pre, conn);rn rn rn rn rn return category;rn rn rn rnrnrn[/code]
Session为什么为空?
<%@ OutputCache Duration="300" VaryByParam="id" %>rnrnrnpublic static string s1(HttpContext context)rn rn if (context.Session == null)rn rn return "null";rn rn elsern rn return "not null"rn rn rnrn只有在第一次不是调用缓存输出的时候Session不为空,rn后续如果都是调用缓存输出Session都为空。rn请问这是什么原因?
session 对象为空
if (System.Web.HttpContext.Current.Session != null && System.Web.HttpContext.Current.Session["FX_ServerUrl"] != null)rn rn wfp.Server.WFPWS_DataSource.setServerUrl(System.Web.HttpContext.Current.Session["FX_ServerUrl"].ToString(), 0);rnrn rn在一个类里写了个这个,调试时直接跳过 这步,session对象为空 ,但以前将一些值保存在session里了,rn为啥会为空
判断session为空
从access数据库中读出的一个文本类型的字段,但是该字段里面没有内容,把这个字段赋值给session("UserName")rnrn[code=VBScript]rnif session("UserName") = null thenrn response.write "UserName空"rnelsern response.write "UserName不为空"rnend ifrn[/code] rn为什么总是执行response.write "UserName不为空"这句rn使用session("UserName") = ”“也是执行rnresponse.write "UserName不为空"rn如果使用session("UserName") is nothing判断提示缺少对象rnrn使用的是vbscript
asp session 为空
[code=VBScript]rnusername=cstr(trim(request("username")))rnpassword=cstr(trim(request("password")))rnif username<>"" and password<>"" thenrn password=md5(password)rn Set rs=Server.CreateObject("ADODB.Recordset")rn sql="SELECT * FROM admin where username='"&username&"' and password='"&password&"' order by id desc"rn rs.Open sql,conn,3,3rn if not rs.eof thenrnrn session("id")=rs("id")rn session("username")=rs("username")rn session("adddate")=rs("adddate")rn Select Case rs("manage")rn case 1rn response.redirect "manage.asp"[color=#FF0000]//这里跳转,跳转前session有值[/color] case 2rn response.redirect "manage2.asp"rn Case Else rn response.redirect "manage3.asp"rn End Select rnrn else。。。。。。。。。。。rn[/code]rnmanage.asp头部包含session.asprn[code=VBScript]rnif session("id")="" or session("username")="" thenrnrnresponse.redirect"login.asp?err=请您登陆!"[color=#FF0000]这里获取不到值了跳转到登陆页[/color]rnend ifrn[/code]rnrn1.已查看web源为1rn2.检查所存网页的较新版本设置为自动,每次访问页面时都不行rn3.response.redirect 改为respose.write " " 还是不行rnrn服务器 win2003 +iis6+ie8,服务器上可以获取sessionrn本地 xp+ie8 失败rn求解rn rnrnrn
session 获取值为空
是这样的:用ssh框架做的项目,当用户根据name和passWord登录之后,调用action的login方法,返回一个List的实体类,然后 在保存在session 里面,这样在其他页面的时候可以调用。贴源码:rnjsp:rn*******rn rn姓名:rn密码:rnrnrn****rnaction :rnHttpSession session;rn HttpServletRequest request;rn get、set方法;rn....rnpublic String login()rn List fanList=fanService.login(login.getUserName(), login.getPassWord());rn if(fanList!=null)rn try rn //session = request.getSession(true); rnrn session.setAttribute("fanService", fanList);rn catch (Exception e) rn // TODO: handle exceptionrn e.printStackTrace();rn rn //request.setAttribute("fanList", fanList);rn return "success";rn rn elsern return "fail";rn rnrn问题是:在用session保存时候,老是session=null的异常,fanList是可以取到值的,但是就是不明白session为什么不能保存,是为什么 啊 怎么修改?
项目 配置域名访问
1  购买服务器 和 域名   , 将域名在服务器上绑定 。 域名可能需要备案 。 2  安装tomcat 服务器 ,配置域名,配置项目名称。  tomcat 下 conf /server.xml 把name的值修改成你的域名                   www.test.com" unpackWARs="true" xmlNamespaceAware="false
关于IP访问和域名访问的SESSION问题
大家好:rnrn 我这有个问题,我的一个工程,配置到tomcat5.5下,rn 情况是这样的:用IP访问的话,session相关都正常,随时可以读到;rn 但用域名访问,第1次可以得到session,第2次再读session就是空的了,rn 不知道哪的问题呀,server.xml配置如下:rnrnrn rn rn rn rn rn rn rn rn rn rn rn
检查SESSION是否为空
我现在做的是通过继承PAGE类来检查SESSION是否为空,然后其他的每个网页都继承这个类,这样很麻烦,每个网页都需要改动,有没有别的方法可以实现当每个用户访问的时候就会检测SESSION是否为空。可不可以通过WEB.CONFIG文件来做?
如何判断session为空
if (Session["username"] = "")//这行代码有误如何修改?rn rn Response.Redirect("Msg.aspx");rn
javaWEB项目session值为空
我将项目部署到服务器中,项目中有一个用户登录验证,验证码是通过JSP生成图片,登录时将验证码存到session中,在后台取出比较,我在本机访问没有问题,我在服务器中,通过用localhost方式访问时,session是有值的,但通过域名方式访问时,session值为空 请问这是什么原因引起的 项目是部署在tomcat中的
session内容为空的问题
我在几个例子中都遇到相似的问题,如在购物车示例中:rn在处理页面转向的Sevlet程序中:rn...rnbasket=(BasketBean)session.getAttribute(BasketBean.BASKET);rn...rn当运行时总是出现java.lang.NullPointerException.rn如果客户不是第一次访问session,则不出错.如果是第一次则必定出错.rn1.难道每次使用前都需要调用一个初始化程序先初始化session吗?rn2.我想在使用购物车之前都得先登录,是不是登录后session就初始化了.rn请问谁能帮我解开疑团?rn
Session为空的问题.求助
小弟最近学习框架的做法.重写了httpModule中的方法.并在Web.config中设置了rn[code=XML]rnrn rnrnrn rn rnrn[/code]rn所以导致Session为null([color=#FF0000]注意,是Session为null 不是Session["xxx"]为null[/color]);rn基本的猜想可能是因为重写了.net处理页面的方式.导致Session没有被正确的初始化..试过两个方法.一个是用rn[code=C#]HttpApplication.Context.Session[/code]rn另一个是用rn[code=C#]HttpContext.Current.Session[/code]rn都为null.请教如何才可以把这个Session初始化呢..rn另外..能否有大侠告知下.net的Session实现原理....?
为什么用session传值为空?
member_login_do.phprnrnrn0 ) //查看返回的查询结果行数rn rn session_id(SID);rn session_start(); //登陆成功,设置SESSION值rn $_SESSION['member'] = $_POST['txt_username']; rn //session_write_close();rn echo " ";rn //exit(0);rn rn elsern rn echo " ";rn rn rn else rn rn echo " ";rn rn ?>rn
tomcat 设置域名访问项目
域名访问项目 首先自己需要一个服务器,并且可以通过    ip + 端口 + 项目    的方式访问项目 http://192.168.1.1:8080/pome    然后 自己购买的域名 需要已备案 通过tomcat设置之后 可以通过 域名的方式访问 http://www.xxxxx.com/  或   xxxx.com   在tomcat conf 文件下 更改以下三个...
通过域名访问项目,tomcat配置
其实很多时候为了面子工程我们都会配置域名映射,通过域名来访问我们的java web项目,显得更加友好和上档次 举例tomcat配置: 关于域名和公网ip以及开设端口的操作就不作赘述了:访问域名直接到项目 关键在tomcat中的一句话是: <!-- Licensed to the Apache Software Foundation (ASF) under one or more c
tomcat 配置域名访问项目
域名访问两步骤:    1.配置端口号为80,8080为默认的端口号。80,可以在地址栏不用写    2.配置Catalina,在Engine 标签中,defaultHost 属性配置为 localhost。这里边他们说配置为你的域名,很抱歉,我也这样配置了,出不来。    既然配置了defaultHost ,那么 host的 name属性也为localhost。这样就出来了。...
vue项目配置域名访问
一,配置 配置文件project_vue/config/index.js 找到 host: (填写域名) port: (填写端口) 二,报错 三,解决报错 在/etc/hosts增加本地解析 (windows自行找hosts文件位置) 0.0.0.0 xxx.yuming.com (这是允许所有ip访问) 四,重启...
nginx+tomcat 通过域名访问项目
之前对于使用域名如何访问项目很好奇,但苦于搞一个自己的域名实在是太麻烦了,还需要去买,各种提交资料,等待审核,备案。。。现在手上没什么项目,也什么事情,想着折腾折腾。。。 看着腾讯服务器打折,花了40块钱大洋买了一个最低版本的服务器(穷,没办法,反正个人用用够了),这里不得不吐槽一下腾讯,安全级别设那么高干嘛,直接远程登录不行,因为ip都ping不通,还有各种端口、命令全部禁掉,因为之前用过阿里...
二级域名怎么访问一级域名的session
假如我有一个域名是www.aaa.comrnrn现在我想在bbb.aaa.com里面调用www.aaa.com里面的sessionrnrn假如www.aaa.com登录后,session是这样的rn Session.Add("aaa_User_Session","我是父的");rnrnrn我怎么在bbb.ass.com里面调用aaa_User_session????
域名和ip访问产生的session不同
测试环境测试支付宝支付,以ip方式访问,而支付宝支付成功后回调地址配置的是域名形式的。造成支付成功后访问成功页面进入了登录页面 同一个网站,通过域名登录和通过IP登录,所产生的session是不相同的,如果希望使用登录时的session信息,那么调用的时候需要注意与登录方式(域名还是IP)保持一致才可以。
用域名访问程序 session 失效
我最近刚开始写WAP程序,比较菜,今天出现的问题在网上也没有找到解决办法,请教各位能帮忙解决下。我用的是tomcat6.0.18,刚开始用本地做测试时没有问题,http://192.168.0.164:8080/wapTest 访问程序没有问题 session也支持,能够传送数据,但到域名访问的时候就出现了session里边的数据为空,获取不到数据rntomcat就修改了 service.xmlrnrn rn rn我用的是winwap浏览的程序,不知道怎么回事,有能解决下的吗?
CVS下载项目为空
我的同事在cvs下载项目很正常,而我却发现要下载的项目是空的。这是为什么?rn
求教:网络连接下的项目为空??
winXP sp2进入控制面板-网络连接,下面的项目为空是怎么回事?rn那位高手遇到过吗?无法上网,该怎么解决?
session 为空写入问题,自己写了一个过滤器获取session为空时写入处理
[code=Java]rn public void doFilter(ServletRequest servletRequest,rn ServletResponse servletResponse, FilterChain filterChain)rn throws IOException, ServletException rnrn /**rn * 1,doFilter方法的第一个参数为ServletRequest对象。此对象给过滤器提供了对进入的信息(包括rn * 表单数据、cookie和HTTP请求头)的完全访问。第二个参数为ServletResponse,通常在简单的过rn * 滤器中忽略此参数。最后一个参数为FilterChain,此参数用来调用servlet或JSP页。rn */rn HttpServletRequest request = (HttpServletRequest) servletRequest;rn /**rn * 如果处理HTTP请求,并且需要访问诸如getHeader或getCookies等在ServletRequest中rn * 无法得到的方法,就要把此request对象构造成HttpServletRequestrn */rn HttpServletResponse response = (HttpServletResponse) servletResponse;rn HttpSession session = request.getSession(false);rn String currentURL = request.getRequestURI(); // 取得根目录所对应的绝对路径:rn System.out.println(currentURL);rn Iterator iter = securityResourcesServicern .getSystemResources().iterator();rn if(session!=null)rn if(currentURL.indexOf("Login")<0&&currentURL.indexOf("validateCode")<0)rn [color=#FF0000]session.setAttribute(Procedure.URL_BLACK, currentURL);[/color]rn rn rn while (iter.hasNext()) rn Resources source = iter.next();rn // 路径格式 /onionPortal/adver/rn if (Pattern.matches(source.getUrl() + "\\S*\\s*", currentURL)) rn System.out.println("拦截认证请求成功!");rn rn if (session == null || session.getAttribute("user") == null) rn System.out.println("----sessionKey:"+Procedure.LAST_LOGIN_IP_SESSION_KEY);rn [color=#FF0000]session.setAttribute(Procedure.LAST_LOGIN_IP_SESSION_KEY,getIpAddrByRequest(request));[/color]rn // *用户登录以后需手动添加sessionrn System.out.println("request.getContextPath()="rn + request.getContextPath());rn response.sendRedirect(request.getContextPath()rn + "/userLogin/middlePage.html");rn return;rn else rn Usertable users = (Usertable) session.getAttribute("user");rn Iterator sourceRole = source.getRole().iterator();rn re:rn while (sourceRole.hasNext()) rn Role role = sourceRole.next();rn Iterator usrRoleiter = users.getRoles()rn .iterator();rn while (usrRoleiter.hasNext()) rn if (role.getId() == usrRoleiter.next().getId()) //如果匹配上则跳出循环rn break re;rn rn rn //跳到登录页面rn response.sendRedirect(request.getContextPath()+ "/userLogin/middlePage.html");rn rn rn rn break;rn rnrn // 加入filter链继续向下执行rn filterChain.doFilter(request, response);rn /**rn * 调用FilterChain对象的doFilter方法。Filter接口的doFilter方法取一个FilterChain对象作 为它rn * 的一个参数。在调用此对象的doFilter方法时,激活下一个相关的过滤器。如果没有另rn * 一个过滤器与servlet或JSP页面关联,则servlet或JSP页面被激活。rn */rn rn[/code]rnrn这里是写的过滤方法!但是如果session为空时怎么写不进去session啊!我需要将用户登录ip写进去红色部分为报错代码rn[color=#FF0000]session.setAttribute(Procedure.URL_BLACK, currentURL);[/color]rn[color=#FF0000]session.setAttribute(Procedure.LAST_LOGIN_IP_SESSION_KEY,getIpAddrByRequest(request));[/color]rn下面是报错代码rnrnrn2012-3-31 22:31:17 org.apache.catalina.core.StandardWrapperValve invokern严重: Servlet.service() for servlet default threw exceptionrnjava.lang.NullPointerExceptionrn at com.onionportal.filter.SecurityFilter.doFilter(SecurityFilter.java:70)rn at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:237)rn at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:167)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)rn at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198)rn at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)rn at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:228)rn at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)rn at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)rn at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)rn at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)rn at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:216)rn at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)rn at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:634)rn at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:445)rn at java.lang.Thread.run(Thread.java:619)rnrnrn求大神解答疑问
Tomcat配置访问域名访问项目及内网访问tomcat管理页面
一般情况下,要向访问服务器的某个系统时,域名+项目名才能访问。通过配置tomcat的xml文件即可在访问项目是访问指定的项目。 【1】更改tomcat的server.xml的8080端口为80端口 【2】修改Engine的defaultHost="localhost" 把localhost换成你的域名,,注意只是域名,域名,域名,不带http或https的那种!!!下面也是 【3】修...
如何判断session("aaa")是否为空?
如何判断session("aaa")是否为空?rn我用 if isnull(session("aaa")) thenrn判断,结果,次次都说not null 。 但明明服务器没有这歌session。rnso,请教,如何判断session("aaa") 是否为空?rn
判断session中是否为空
判断userInfo在session中是否为空 Object obj = session.getAttribute(&quot;userInfo&quot;);            if(obj==null){}
struts标签判断session的值是否为空
亮点:[color=yellow][size=xx-large][/size][/color] [code=&quot;jsp&quot;] [/code]
使用拦截器验证session是否为空
第一步、定义一个拦截器: public class UserInterceptor extends AbstractInterceptor { private static String AUTH_SESSION_USER_KEY=&quot;userInfo&quot;;//从session中获取userInfo private static String NO_LOGIN=&quot;index&quot;;//ses...
怎样判断一个session是否为空?
if(Session["boardid"]!=NULL)rn.................................NULL is not defined in c#???rnrnif(Session["boardid"].ToString()!="")rn..................................it works bad,why?rn..................................I used the code:Session["boardid"]="1",any problem?rnrndo someone hace some other ways?rn3x!
判断session是否为空的问题 +100
[code=csharp]public string getPower()rn rn rn string name = Session["username"].ToString();rn return new UserManager().getUserByName(name).U_signer;rn rn [/code]rnrn我想加一个session是否为空
关于判断session是否为空的问题。
if (Session["admin"] == null)rn rn Response.Redirect("LoginRegis.aspx?page=Default.aspx");rn rnrnrn当我登录了。Session["admin"]就有值了。然后就可以进入这个页面。rnrn有用户跟我反应,管理页面可以随便进入。是不是他进入的时候这个Session["admin"]不等于null?rnrn难道是其它人可以读取到我登录创建的Session["admin"] ?rnrn服务器应该是为每一个用户创建一个Session["admin"] 的吧。rnrn难道是只要有一个人创建了Session["admin"] 。其它人都可以进入这个页面了?
struts2 通过ioc获取session为空
最近在学struts2,定义了一个BaseAction通过IoC方式实现SessionAware接口获取session,其他类想用session的时候继承BaseAction,但是出现session为空,不知道为什么?代码如下rnBaseAction类:rn[code=java]package common;rnrnimport java.util.Map;rnrnimport org.apache.struts2.interceptor.RequestAware;rnimport org.apache.struts2.interceptor.SessionAware;rnrnimport com.opensymphony.xwork2.ActionSupport;rnrn/**rn * @author qgs Class Description:用户Action类 Created Time:2014-3-17 下午02:45:35rn */rnpublic class BaseAction extends ActionSupport implements SessionAware,RequestAware rnrn /* rn 获取request,response,session方式一,非IoC方式,不用实现SessionAware,rn ServletRequestAware, ServletResponseAwarern ActionContext context = ActionContext.getContext();rn HttpServletRequest request = (HttpServletRequest)rn context.get(ServletActionContext.HTTP_REQUEST);rn HttpServletResponse response = (HttpServletResponse)rn context.get(ServletActionContext.HTTP_RESPONSE);rn Map session = context.getSession();rn SessionMap session = (SessionMap) context.get(ActionContext.SESSION);rnrn 获取request,response,session方式一,IoC方式,必须实现SessionAware,rn RequestAware或者ServletRequestAware, ServletResponseAwarern */rnrn private static final long serialVersionUID = 1L;rnrn private Map request;rn private Map session;rn private Map application;rn rn public Map getApplication() rn return application;rn rn rn public Map getRequest() rn return request;rn rn public Map getSession() rn return session;rn rn public void setApplication(Map application) rn this.application = application;rn rn public void setRequest(Map request) rn this.request = request;rn rn public void setSession(Map session) rn this.session = session;rn rnrnrnrn[/code]rnUserAction类:rn[code=java]package kmust.liip.testcenter.userright.action;rnrnimport java.util.ArrayList;rnimport java.util.List;rnrnimport kmust.liip.testcenter.userright.dao.BaseDao;rnimport kmust.liip.testcenter.userright.dao.RightSeqDaoImpl;rnimport kmust.liip.testcenter.userright.dao.UserDao;rnimport kmust.liip.testcenter.userright.dao.UserDaoImpl;rnimport kmust.liip.testcenter.userright.model.User;rnrnimport org.hibernate.HibernateException;rnrnimport common.BaseAction;rnrn/**rn * @author qgsrn * Class Description:用户Action类rn * Created Time:2014-3-17 下午02:45:35rn */rnpublic class UserAction extends BaseAction rnrn private static final long serialVersionUID = 1L;rnrn private User user;rnrn //用户登录rn public String login() rn String usercode = this.user.getUsercode();rn String userpwd = this.user.getUserpwd();rn UserDao userdao = new UserDaoImpl();rn User u;rn try rn //通过登录表单传的usercode查询数据库的用户rn u = userdao.getById("usercode",usercode);rn if(u == null) rn addFieldError("loginerror", "用户名不存在");rn return "input";rn rn if (!u.getUserpwd().equals(userpwd)) rn addFieldError("loginerror", "密码不正确");rn return "input";rn rn //根据用户代码得到用户功能序号串rn String rightseq = userdao.getRightSeq(usercode);rn u.setRightseq(rightseq);rn //保存用户登录信息rn this.getSession().put("usersession", u);rn return "success";rn catch (HibernateException e) rn e.printStackTrace();rn return "fail";rn rn rnrn public void setUser(User user) rn this.user = user;rn rn rn public User getUser() rn return user;rn rnrn[/code]rnManageUserLogDaoImpl 类:rn[code=java]package kmust.liip.testcenter.userright.dao;rnrnimport java.util.List;rnrnimport kmust.liip.testcenter.userright.model.ManageUserLog;rnimport kmust.liip.testcenter.userright.model.User;rnrnimport org.apache.struts2.ServletActionContext;rnrnimport com.opensymphony.xwork2.ActionContext;rnimport common.BaseAction;rnrnpublic class ManageUserLogDaoImpl extends BaseAction implements ManageUserLogDao rn private static final long serialVersionUID = 1L;rn private BaseDao basedao;rn private ManageUserLog manageUserLog;rn rn public void save() rn Map session = this.getSession();rn User user = (User)session.get("usersession");rn //User user = (User)ActionContext.getContext().getSession().get("usersession");rn String action = "添加用户";rn String ip = ServletActionContext.getRequest().getRemoteAddr();rn manageUserLog.init(action, ip, user.getUsercode(), user.getUsername());rn this.basedao.save(manageUserLog);rn rn rnrn[/code]rnManageUserLogDaoImpl 继承BaseAction,在save方法中,debug发现this.session为空,而ActionContext.getContext().getSession()可以获取到session,登录时放进去的usersession也可以得到,求解?
如何判断SESSION的值为空啊?
如何判断SESSION的值为空啊?rn另外,如果要把一个DataSet赋值给SESSION,rn如何赋值啊?以及如何取各字段的值呢?
如何判断session对象为空????
请问如何判断session对象为空????rnrnif (session.getValue("id"))rn out.println("Error!");rnrn我这样写的,我用equals函数不管用!!!rn请问如何当这个session为空时,输出“Error”,而不是报错???
spring 管理hibernate session 为空
session.createQuery 报空指针rn代码如下:rn接口:rnpublic interface TbUserSpringDAO rn public void register(TbUser user);rn public TbUser findById(int id);rn public List findAll();rn public TbUser LoginValidate(String username,String password);rn rnrn实现类rnpublic class ImplTbUserSpringDAO implements TbUserSpringDAO rn private TbUserDAO userdao;rn rn public void setUserdao(TbUserDAO userdao) rn this.userdao = userdao;rn rnrn public List findAll() rn // TODO Auto-generated method stubrn return userdao.find();rn rnrn public TbUser findById(int id) rn // TODO Auto-generated method stubrn return userdao.findById(id);rn rnrn public void register(TbUser user) rn // TODO Auto-generated method stubrn userdao.save(user);rn rnrn public TbUser LoginValidate(String username, String password) rn // TODO Auto-generated method stubrn return userdao.loginValidate(username,password); rn rnrn public TbUserDAO getUserdao() rn return userdao;rn rnrnrnrnrnpublic interface TbUserDAOrn public void delete(TbUser user);rn public List find();rn public TbUser findById(int id);rn public void save(TbUser user);rn public TbUser loginValidate(String username,String password);rnrnrnpublic class ImplTbUserDAO extends HibernateDaoSupport implements TbUserDAO rnrn public void delete(TbUser user) rn this.getHibernateTemplate().delete(user);rn rnrn public List find() rn // TODO Auto-generated method stubrn String hql = "from TbUser";rn return this.getHibernateTemplate().find(hql);rn rnrn public TbUser findById(int id) rn // TODO Auto-generated method stubrn String hql = "from TbUser as tu where tu.iuserId=:iuserId";rn return (TbUser) this.getHibernateTemplate().findByNamedParam(hql, "iuserId", id).get(0);rn rnrn public void save(TbUser user) rn // TODO Auto-generated method stubrn this.getHibernateTemplate().saveOrUpdate(user);rn rnrn public TbUser loginValidate(String username, String password) rn // TODO Auto-generated method stubrn return (TbUser)this.getHibernateTemplate().execute(rn new HibernateCallback()rn public Object doInHibernate (Session session)throws HibernateException, SQLExceptionrn String hql = "from TbUser as tu where tu.vcUserName = : username and tu.vcPassWord = : password";rn Query query = session.createQuery(hql);rn TbUser tbuser = (TbUser) query.list();rn return tbuser;rn rn rn );rn rnrn
验证码验证的时候,Session总是为空
1.validatepage.aspx页面中:rn protected void Page_Load(object sender, EventArgs e)rn rn gif = RndNum();//获得验证码rn ...rn rn Session["validator"] = gif; //sessionrnrn rn2. 在注册页面中想取出Session内容rn protected void Page_Load(object sender, EventArgs e)rn rnrn validationImage.ImageUrl = "validatepage.aspx";rn [color=#FF0000]if (Session["validator"] != null)rn rn lblTemp.Text = Session["validator"].ToString();rn [/color] rn红色的语句始终进不去... rnrnrn请大家帮忙,没有分 不好意思.
相关热词 c# 线程结束时执行 c# kb mb 图片 c# 替换第几位字符 c#项目决定成败 c# 与matlab c# xml缩进 c#传感器基础 c#操作wps c# md5使用方法 c# 引用父窗口的组件