${3+12} <% request.setAttribute("mess","你好"); %>为啥报错啦
时间: 2024-06-06 22:11:29 浏览: 7
Null is a term used in computer programming to indicate the absence of a value or a reference to a nonexistent or undefined object. It is commonly represented as a value of zero or an empty string. In programming languages such as Java, C++, and Python, null is often used to signify the absence of a value in a variable or an object. It is also used to indicate the end of a data structure or a file. Null is an important concept in programming as it helps prevent errors and ensures the correct functioning of programs.
相关问题
HttpSession session = request.getSession(); List<NewInfor> list; NewsService newsService = new NewsService(); //查询所有新闻 list = newsService.getAllNews(); //存入 session.setAttribute("list", list); //跳转页面 request.getRequestDispatcher("/index.jsp").forward(request,response); List<NewInfor> list = (List<NewInfor>) session.getAttribute("list"); for (int i=0; i<list.size(); i++){ NewInfor newInfor = list.get(i); %> <tr> <td> <a href="getInformation?newsId=<%=newInfor.getId()%>"><%= newInfor.getTitle()%></a> </td> <td><%= newInfor.getAuthor()%></td> <td><%= newInfor.getType()%></td> <td><%= newInfor.getTime()%></td> </tr> <% } %>
这段代码是一个JSP页面,首先它通过调用request对象的getSession()方法获取HttpSession对象,然后创建了一个NewsService对象来查询所有新闻并将结果存入HttpSession中,接着通过调用request对象的getRequestDispatcher()方法跳转到index.jsp页面。
在index.jsp页面中,它通过调用session对象的getAttribute()方法获取之前存入的新闻列表,然后使用循环遍历所有新闻并在页面中以表格的形式展示出来,每一行对应一篇新闻,包含该新闻的标题、作者、类型、时间等信息。当用户点击某篇新闻的标题时,它会跳转到getInformation页面并带上该新闻的ID作为参数。
以下JSP代码的执行结果为( )。<% request. setAttribute ("name", "accp") ; %> $name]、$(requestScope.name]、$ (response.name}、$isession.name}、$iapplication. name} (选择一项) A: accp、accp、.、 B: accp、accp、. accp . accpc: accp、 accp、accp 、 accp . accpD: accp、. . ·
A: accp、accp、.、 是正确的结果。
解释如下:
- <% request. setAttribute ("name", "accp") ; %>:设置request作用域中的name属性为"accp"。
- $name:EL表达式获取pageContext作用域中的name属性值,即"accp"。
- $(requestScope.name]:EL表达式获取request作用域中的name属性值,即"accp"。
- $ (response.name}:EL表达式获取response作用域中的name属性值,但是response作用域中没有设置name属性,所以结果为"."。
- $isession.name}:EL表达式获取session作用域中的name属性值,但是没有在session作用域中设置name属性,所以结果为"."。
- $iapplication. name}:EL表达式获取application作用域中的name属性值,但是没有在application作用域中设置name属性,所以结果为"。"。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![text/plain](https://img-home.csdnimg.cn/images/20210720083646.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
还是报错 org.apache.jasper.JasperException: 无法为JSP编译类: JSP文件:[/userList.jsp] 的第 [28] 行发生了一个错误 u cannot be resolved 25: <c:otherwise> 26: <c:forEach var="u" items="${userlist}"> 27: 28: User :<%=u.getUsername()%> 29: Password :<%=u.getPassword()%> 30: Email :<%=u.getEmail()%> 31: Sex :<%=u.getSex()%>
详细解读一下这段代码:<%@ page language="java" import="java.text.*,java.util.*" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>使用application内置对象--checkMessage.jsp</title> </head> <body bgcolor="#abcdef"> <%!Vector<String> v = new Vector<String>(); int i = 0;%> <% String datetime = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(Calendar.getInstance().getTime()); //获取系统时间 %> <% request.setCharacterEncoding("utf-8"); String name = request.getParameter("name"); String title = request.getParameter("title"); String message = request.getParameter("message"); %> <% if (name == null || "".equals(name.trim())) { //trim()主要解决里面只有空格的问题 name = " 网友" + (int) (Math.random() * 100000 + 10000); } if (title == null || "".equals(title.trim())) { title = " 无"; } if (message == null || "".equals(message.trim())) { message = " 无"; } %> <% i++; String str = "第" + "" + i + " " + "楼 " + ".留言人: " + name + ".标题: " + title + ".内容:
" + message + ".时间: " + datetime + ".
"; v.add(str); application.setAttribute("message", v); %> 留言成功. 返回留言板 </body> </html>
<%-- 作者:GGG166 --%> <%@page contentType="text/html;charset=gb2312" %> <%@page import="java.util.*"%> <html> <body> <%! Vector v=new Vector();//动态数组 int i=0; ServletContext application; synchronized void leaveWord(String s){//方法声明,用于在添加评论 application=getServletContext(); i++; v.add("No"+i+","+s); application.setAttribute("Mess",v); } %> <% request.setCharacterEncoding("gb2312");//乱码处理 String name=request.getParameter("name");//接收姓名 String title=request.getParameter("title");//接收标题 String message=request.getParameter("message");//接收评论 if(name==null){ name="guest"+(int)(Math.random()*10000); } if(title==null){ title="无标题"; } if(message==null){ message="无信息"; } String s=name+"#"+title+"#"+message; leaveWord(s); out.print("你的评论已提交!"); %> 返回留言页面 </body> </html>
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
详细解读一下这段代码:<%@ page language="java" import="java.text.*,java.util.*" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>使用application内置对象--checkMessage.jsp</title> </head> <body bgcolor="#abcdef"> <%!Vector<String> v = new Vector<String>(); int i = 0;%> <% String datetime = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(Calendar.getInstance().getTime()); //获取系统时间 %> <% request.setCharacterEncoding("utf-8"); String name = request.getParameter("name"); String title = request.getParameter("title"); String message = request.getParameter("message"); %> <% if (name == null || "".equals(name.trim())) { //trim()主要解决里面只有空格的问题 name = " 网友" + (int) (Math.random() * 100000 + 10000); } if (title == null || "".equals(title.trim())) { title = " 无"; } if (message == null || "".equals(message.trim())) { message = " 无"; } %> <% i++; String str = "第" + "" + i + " " + "楼 " + ".留言人: " + name + ".标题: " + title + ".内容:
" + message + ".时间: " + datetime + ".
"; v.add(str); application.setAttribute("message", v); %> 留言成功. 返回留言板 </body> </html>
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
<%-- 作者:GGG166 --%> <%@page contentType="text/html;charset=gb2312" %> <%@page import="java.util.*"%> <html> <body> <%! Vector v=new Vector();//动态数组 int i=0; ServletContext application; synchronized void leaveWord(String s){//方法声明,用于在添加评论 application=getServletContext(); i++; v.add("No"+i+","+s); application.setAttribute("Mess",v); } %> <% request.setCharacterEncoding("gb2312");//乱码处理 String name=request.getParameter("name");//接收姓名 String title=request.getParameter("title");//接收标题 String message=request.getParameter("message");//接收评论 if(name==null){ name="guest"+(int)(Math.random()*10000); } if(title==null){ title="无标题"; } if(message==null){ message="无信息"; } String s=name+"#"+title+"#"+message; leaveWord(s); out.print("你的评论已提交!"); %> 返回留言页面 </body> </html>
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)