The method setUserid(String) is undefined for the type User
时间: 2023-09-26 22:05:29 浏览: 71
这个错误提示表明在 User 类中没有定义名为 setUserid 的方法,而你的代码中尝试调用了这个方法。
可能的原因是你想要设置 User 对象的 ID,但是没有正确地定义这个方法。你需要检查 User 类的定义,确保它包含一个名为 setUserid 的方法,并且参数类型和返回类型都正确。
如果你找不到问题所在,可以把 User 类的代码贴出来,我可以帮你看看。
相关问题
The method sub(String) is undefined for the type String
As an AI language model, I can say that the error message "The method sub(String) is undefined for the type String" typically occurs when you try to call the sub() method on a String object in Java, but the method is not defined for the String class. The sub() method is used to extract a substring from a String object based on the specified index range.
To resolve this error, you need to ensure that you are calling the sub() method on a valid object that has this method defined. You can also check the Java documentation to verify the syntax and usage of the sub() method.
the method preparement(String) is undefined for the type SQLConn
抱歉,我的回答中有误。应该将SQLConn类中的openDB方法改为返回Connection对象,然后在JSP页面中使用该Connection对象创建PreparedStatement对象。
具体修改如下:
SQLConn.java:
public class SQLConn {
// 省略其他代码
// 修改openDB方法
public static Connection openDB() throws ClassNotFoundException, SQLException {
// 加载JDBC驱动
Class.forName("com.mysql.jdbc.Driver");
// 创建数据库连接
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "123456");
// 返回连接对象
return conn;
}
// 省略其他代码
}
login.jsp:
<%@ page language="java" import="java.util.*, java.sql.*" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>登陆跳转servlet</title>
</head>
<body>
<%
String usernum = request.getParameter("usernum");
String userpwd = request.getParameter("userpwd");
Connection conn = SQLConn.openDB();
// 使用PreparedStatment进行预编译
PreparedStatement pstmt = conn.prepareStatement("select UserId, Code from User_ZC where usernum=? and userpwd=?");
pstmt.setString(1, usernum);
pstmt.setString(2, userpwd);
ResultSet rs = pstmt.executeQuery();
boolean v = rs.next();
rs.close();
pstmt.close();
conn.close();
if(v){
request.getRequestDispatcher("ZCS.jsp").forward(request, response);
}else{
request.getRequestDispatcher("ZCB.jsp").forward(request, response);
}
%>
</body>
</html>
在JSP页面中,我们使用SQLConn类的openDB方法获取数据库连接,然后使用该连接对象创建PreparedStatement对象,设置参数并执行查询。在使用完PreparedStatement和ResultSet之后,及时关闭资源。
再次抱歉给您带来的困扰。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.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)
![](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)