急救!一个关于jsp的小问题!局部变量和全局变量!

JingYDENG 2018-06-05 11:08:52

<%
String[] search = request.getParameterValues("rad");
if (search != null) {
for (int i = 0; i < search.length; i++) {
if (search[i].equals("label")) {
String label=request.getParameter("search");
out.print("检索图片标签:"+label);
}
if (search[i].equals("author")) {
String author=request.getParameter("search");
out.print("检索摄影师用户名:"+author);
}
if (search[i].equals("passage")) {
String passage=request.getParameter("search");
out.print("检索图文关键字:"+passage);
}
if (search[i].equals("type")) {
String type=request.getParameter("type");
out.print("检索图片类型:"+type);
}
}
}
%>
<%=label%>
---------------------------------------------------------
问题:<%=label%>报错了说这个变量不能用 求解 急!!!
页面需要一次性输出label、author、passage、type的值。我应该怎么做?
...全文
1002 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
stacksoverflow 2018-06-14
  • 打赏
  • 举报
回复
作业交了吗?
楓VS痕 2018-06-14
  • 打赏
  • 举报
回复
<% String label = ""; String author = ""; String passage = ""; String type = ""; String[] search = request.getParameterValues("rad"); if (search != null) { for (int i = 0; i < search.length; i++) { if (search[i].equals("label")) { label=request.getParameter("search"); out.print("检索图片标签:"+label); } if (search[i].equals("author")) { author=request.getParameter("search"); out.print("检索摄影师用户名:"+author); } if (search[i].equals("passage")) { passage=request.getParameter("search"); out.print("检索图文关键字:"+passage); } if (search[i].equals("type")) { type=request.getParameter("type"); out.print("检索图片类型:"+type); } } } %> <%=label%>
sq1303037035 2018-06-08
  • 打赏
  • 举报
回复
String label=request.getParameter("search");这个放在if里,作用域是if里 可以把句放在String[] search = request.getParameterValues("rad");下边
南国的风雪 2018-06-06
  • 打赏
  • 举报
回复
这当然不能用啊,你的lable定义在if里面,在外面取不到
Legendary灬 2018-06-06
  • 打赏
  • 举报
回复
你上面定义 String label 写在了if里面 ,当然是作用域只在if里,拿到最外面定义这个变量
zjfchinese 2018-06-06
  • 打赏
  • 举报
回复
这个label是不是要pageContext.setAttribute("label",label)后,下面<%=label%>才能取啊?好久没做jsp了,就跟着印象猜猜
诺丽果 2018-06-06
  • 打赏
  • 举报
回复
你search[i]里面有没有label这个字段啊,不行你就换个别的名字试试
yjsl__ 2018-06-05
  • 打赏
  • 举报
回复
能用的,报什么错
JingYDENG 2018-06-05
  • 打赏
  • 举报
回复
JingYDENG 2018-06-05
  • 打赏
  • 举报
回复
希望大家帮帮忙 马上要交作业了~

81,090

社区成员

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

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