session里定义数组的问题

kulasama 2004-09-23 08:05:19
有一个session属性。。是描述斑竹可以控制的板块的。eidtor_forum_id
是用数组来表示的。。现在。。我用下面语句取出session属性
String[] editor_forum_id=new String[10];
editor_forum_id[]=(String)session.getAttribute("editor_forum_id");
错误是
not a statement
editor_forum_id[]=(String)session.getAttribute("editor_forum_id");
请问问题是什么。。我该怎么样取出session值?
还有。。。这个session是用
session.setAttribute("editor_forum_id","123")写入的。请问这样的写法是否正确?
...全文
227 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
kulasama 2004-09-24
  • 打赏
  • 举报
回复
晕。。搞错了。。两边的变量不是一个类型。。
kulasama 2004-09-23
  • 打赏
  • 举报
回复
恩。。谢谢。。还没注意到呢。。。
对了。
错误:operator == cannot be applied to int,java.lang.String
if(editor_forum_id_int[i]==forumid)
是什么意思。。
命名时不能用int吗?
阿土伯伯 2004-09-23
  • 打赏
  • 举报
回复
editor_forum_id[]=(String[])session.getAttribute("editor_forum_id");
应该为:
editor_forum_id=(String[])session.getAttribute("editor_forum_id");//
kulasama 2004-09-23
  • 打赏
  • 举报
回复
第2个页面DeleteTopic.jsp

<%@ page contentType="text/html;charset=gb2312" language="java"
import="java.sql.*,java.io.*"errorPage="error.jsp"%>
<html>
<head>
<title>生成session和判断权限</title></head>
<body>
<%

String forumid="";// 板块id
String user_right="";//用户权限
String user_islogin="";//是否登陆
String[] editor_forum_id=new String[10];//斑竹管理的板块
int user_right_int=0;//初始化
int editor_forum_id_int[]=new int[10];//初始化
forumid=request.getParameter("forumid");
user_right=(String)session.getAttribute("user_right");
user_islogin=(String)session.getAttribute("user_login");
editor_forum_id[]=(String[])session.getAttribute("editor_forum_id");//从session中取得斑竹管理的板块值
user_right_int=Integer.parseInt(user_right);//将用户权限转为整形
for(int i=0;i<editor_forum_id.length;i++)//将斑竹管理的板块转成整形
{
editor_forum_id_int[i]=Integer.parseInt(editor_forum_id[i]);
}
if(user_islogin.equals("no"))//如果没有登陆,就跳出
response.sendRedirect("error.jsp?message=1");
if(user_right.equals("2"))//如果用户权限为普通用户。就没有权限删除帖子
response.sendRedirect("error.jsp?message=2");
if(user_right.equals("1"))//如果用户权限为斑竹,就执行下面的操作
{
for(int i=0;i<editor_forum_id_int.length;i++)//如果斑竹管理的板块是该帖子的板块,就执行下面的操作
{
if(editor_forum_id_int[i]==forumid)
response.sendRedirect("delete.jsp");
}
response.sendRedirect("error.jsp?message=2");//否则跳出
}
else
response.sendRedirect("delete.jsp");//如果用户权限不是普通用户或是斑竹。。那就一定是管理员。执行delete操作。

%>
</body>
</html>
kulasama 2004-09-23
  • 打赏
  • 举报
回复
第一个页面 makesession.jsp
<%
String e[]=new String[]{"2","3","4"};

session.setAttribute("user_right","1");
session.setAttribute("user_login","true");
session.setAttribute("editor_forum_id",e);
%>
<html>
<head>
<title>makesession</title></head>
<body>
<form method="post"action="DeleteTopic.jsp">
<p>板块id
<input type="text"name="forumid">
<p>帖子id
<input type="text"name="topicid">
<input type="submit"name="submit"value="提交">
</form>
</body>
</html>
kulasama 2004-09-23
  • 打赏
  • 举报
回复
那就奇怪了。。改了好多地方。。结果问题依然是前面的。。一点都没有变。。我把代码都贴出来吧。。。。。帮忙看看是什么地方出错了。。
阿土伯伯 2004-09-23
  • 打赏
  • 举报
回复
request.getSession().setAttribute(("edit",e);是正确的。
kulasama 2004-09-23
  • 打赏
  • 举报
回复
恩。。那在session里面添加数组是怎么样呢?
String[] e=new String[]("1","2","3");
setAttribute("edit",e);
这样写对吗?e要不要加引号?
阿土伯伯 2004-09-23
  • 打赏
  • 举报
回复
新建字符串数组并给字符串数组赋值应该为String[] x=new String[]{"sdf","sdkf"};
kulasama 2004-09-23
  • 打赏
  • 举报
回复
对了。。。显式变化也是这样。。
not a statement
editor_forum_id[]=(String[])session.getAttribute("editor_forum_id");//
我现在怀疑是我的session赋值问题。。。
kulasama 2004-09-23
  • 打赏
  • 举报
回复
哈谢谢。。。对了。。能否讲解一下java字符串数组问题。。
给一个字符串赋值要新建一个对象。。那给一个字符串数组赋值呢?
new String[x1,x2,x3];?
一点晴 2004-09-23
  • 打赏
  • 举报
回复

楼上正解,显式转换应该是(String[]);

另';' expected的意思是,你的程序某处漏掉了分号,或语法格式错误。
jiziba 2004-09-23
  • 打赏
  • 举报
回复
editor_forum_id=(String[])session.getAttribute("editor_forum_id");
kulasama 2004-09-23
  • 打赏
  • 举报
回复
同时还有这个错误
';' expected
editor_forum_id[]=(String)session.getAttribute("editor_forum_id");//

81,091

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧