下面是一个用于从 jsp 页面获取参数的 servlet。
我正在尝试运行以下代码-
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.swing.JFrame;
public class oneServlet extends HttpServlet {
public static Connection getConnection() throws Exception {
String driver = "org.postgresql.Driver";
String url = "jdbc:postgresql://10.1.11.112:5432/pack";
String username = "pack";
String password = "pack";
Class.forName(driver);
Connection conn = DriverManager.getConnection(url, username, password);
return conn;
}
public static void main(String[] args) throws Exception {
String user=request.getParameter("t1");
String pass=request.getParameter("t2");
Connection conn = null;
PreparedStatement pstmt = null;
try {
conn = getConnection();
String queryTest = "select username,password from login";
pstmt = conn.prepareStatement(queryTest);
ResultSet rs = pstmt.executeQuery();
while (rs.next()) {
String username=rs.getString(1);
String password=rs.getString(2);
if(user.equals(username) && pass.equals(password))
{
JFrame frame = new JFrame("/LoginSuccess.jsp");
}
else
{
System.out.println("Login Failed,Please try Againe");
}
}}
catch (Exception e) {
e.printStackTrace();
} finally {
pstmt.close();
conn.close();
}
}
}
它在 request.getParameter 中显示“请求无法解析”的错误。任何人都可以帮我解决这个问题。