String stuNo = properties.getProperty("stuNo");什么意思
时间: 2024-05-29 16:14:33 浏览: 9
这行代码是从一个 Properties 对象中获取名为 "stuNo" 的属性值,并将其赋值给 String 类型的变量 stuNo。Properties 对象通常用于存储配置信息或者其他类型的键值对数据。getProperty 方法是 Properties 类提供的获取属性值的方法。如果找不到指定的属性,则该方法将返回 null。
相关问题
int stuNo = Integer.parseInt(properties.getProperty("student.stuNo"));什么意思
这行代码是从 Java Properties 对象中获取名为 "student.stuNo" 的属性值,然后将其解析为整数类型并赋值给变量 stuNo。通常情况下,Properties 对象是用来存储配置信息的,所以这行代码的作用是获取名为 "student.stuNo" 的配置项的值,并将其转换为整数类型以便后续使用。如果属性不存在或无法解析为整数,则会抛出 NumberFormatException 异常。
//先判断类 String str = in.nextLine(); int length = str.length(); //学生PT if(length == 0) { String stuNo1 = in.next(); String name1 = in.next(); double english1 = in.nextDouble(); double math1 = in.nextDouble(); double Java1 = in.nextDouble(); double testScore1 = 1.0; Student s1 = new StudentPT(stuNo1,name1,english1,math1,Java1,testScore1); System.out.println(s1.toString()); } 如何修改
这段代码中的if语句块可以进行如下修改:
```java
// 判断输入字符串是否为"PT"
String str = in.nextLine();
if(str.equals("PT")) {
String stuNo1 = in.next();
String name1 = in.next();
double english1 = in.nextDouble();
double math1 = in.nextDouble();
double java1 = in.nextDouble();
double testScore1 = 1.0;
// 创建一个学生对象,类型为StudentPT
Student s1 = new StudentPT(stuNo1, name1, english1, math1, java1, testScore1);
System.out.println(s1.toString());
}
```
这样修改后,就可以根据输入的字符串是否为"PT"来判断要创建的学生对象类型,并且按照相应的属性值创建对象。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.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)
帮我找到代码中的错误 ReStu.connect(); //判断请求参数的合法性 String stuno = new String(request.getParameter("StuNo").trim().getBytes("iso8859_1")); String stuname = new String(request.getParameter("StuName").trim().getBytes("iso8859_1")); String password = new String(request.getParameter("Pswd").trim().getBytes("iso8859_1")); ResultSet rs = ReStu.QueryStu(stuno); //获取rs里查到的学号,和姓名,准备进行匹配 while (rs.next()){ String str1 = rs.getString(1); String str2 = rs.getString(2); if (str1.equals(stuno)&str2.equals(stuname)){ int i = ReStu.UpdPw(password,stuno); if(i>0){ out.println("注册成功");}%> 注册成功 <% }}%> 去登录 <% ReStu.close_all();%>
![](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)