if (key == null || key.equals("")) { int currentIndex, count, size = 10; String index = request.getParameter("index"); if (index == null) index = "1"; currentIndex = Integer.parseInt(index); try { StudentD sdao = new StudentD(); ArrayList<Student> stus = sdao.getOnePage(currentIndex, size); count = sdao.getStudentCount(); int sumIndex = count % size == 0 ? count / size : count / size + 1; session.setAttribute("onePageStudent", stus); session.setAttribute("sumIndex", sumIndex); response.sendRedirect("teacher/main.jsp"); } catch (Exception e) { out.print(e); } }
时间: 2024-02-01 20:04:07 浏览: 26
这段代码的作用是检查一个名为key的变量是否为空或空字符串。如果不是空的,那么代码将不执行任何操作。如果是空的,则会从请求参数中获取名为index的参数的值,并将其转换为整数类型。然后,它使用StudentD类从数据库中获取指定索引(即currentIndex)的学生列表,并计算学生总数和页数。最后,它将学生列表和页数存储在会话中,并将响应重定向到"teacher/main.jsp"页面。如果在此过程中发生异常,将打印该异常。
相关问题
<% request.setCharacterEncoding("UTF-8"); String usr = request.getParameter("username"); String pwd1 = request.getParameter("password1"); String pwd2 = request.getParameter("password2"); if (usr == null || usr.equals("") || pwd1 == null || pwd1.equals("") || pwd2 == null || pwd2.equals("")) { response.sendRedirect("register.jsp"); out.print("<h1>请完善你的信息"); }// 参数错误 else if (!pwd1.equals(pwd2)) { response.sendRedirect("register.jsp"); out.print("<h1>两次输入密码不一致"); // 两次输入密码不一致 } %>这段代码什么意思
这段代码是一个 Java Servlet/JSP 页面,用于处理用户注册信息。它首先从 HTTP 请求中获取用户名、密码1和密码2,然后检查这些参数是否为空。如果任何一个参数为空,它将重定向到注册页面并打印一个错误消息。如果密码1和密码2不匹配,则它也会重定向到注册页面并打印错误消息。否则,它将继续处理用户注册信息。
逐步解析代码:public static String getIpAddr(HttpServletRequest request) { if (request == null) { return "unknown"; } String ip = request.getHeader("x-forwarded-for"); if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { ip = request.getHeader("Proxy-Client-IP"); } if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { ip = request.getHeader("X-Forwarded-For"); } if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { ip = request.getHeader("WL-Proxy-Client-IP"); } if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { ip = request.getHeader("X-Real-IP"); } if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { ip = request.getRemoteAddr(); } return "0:0:0:0:0:0:0:1".equals(ip) ? "127.0.0.1" : getMultistageReverseProxyIp(ip); }
这段代码是用来获取用户访问的IP地址的。首先判断请求对象是否存在,如果不存在,返回"unknown"。然后通过 request.getHeader() 方法获取各种可能的客户端IP地址,如果为空或者为"unknown",继续获取下一个可能的IP地址,直到最后一个获取不到时,返回 request.getRemoteAddr() 方法获取的IP地址。最后判断获取到的IP地址是否是"0:0:0:0:0:0:0:1",如果是,则将IP地址替换为"127.0.0.1",否则调用 getMultistageReverseProxyIp() 方法处理IP地址并返回。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.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)
下列代码: <% ReStu.connect(); String stuno=new String(request.getParameter("StuNo").trim().getBytes("iso8859_1")); String password=new String(request.getParameter("Pswd").trim().getBytes("iso8859_1")); if(stuno==null || password==null || stuno.equals("") || password.equals("")){ out.println("信息不完整,请重新输入"); %> 返回登录 <%} else{ ResultSet rs=ReStu.QueryStuLog(stuno,password); if(rs.next()){ String stuname=rs.getString("StuName"); //这句要注意,session的还没看!! // session.setAttribute("StuName",stuname); out.println("succeess"); //response.sendRedirect("index.html"); }} ReStu.close_all();%>,运行后抛出异常:org.apache.jasper.JasperException: java.lang.NullPointerException org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:500) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:428) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260) javax.servlet.http.HttpServlet.service(HttpServlet.java:717,找出错误原因
![](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)
![](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)