gpt4 book ai didi

java - 如何从 JSP 页面获取登录信息?我怎样才能更正我的jsp代码。?

转载 作者:行者123 更新时间:2023-11-29 06:10:16 24 4
gpt4 key购买 nike

我这里错了我该如何更正

String Sql="select * from login where username='"+name+"' AND password='"+abc+"'";
c1.st.executeQuery(Sql);
{
out.println("aa");
}
catch(SQLException ex)
{

我只是错了,这是jsp中的登录页面。我只是错了,这是jsp中的登录页面。

数据库conn.jsp

 <%@page import="com.mysql.jdbc.Connection"%>
<%@page import="com.mysql.jdbc.Statement"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.DriverManager"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1>Hello World!</h1>

<%@ page import ="java.sql.*" %>
<%
Connection c1 = null;
Statement st = null;
ResultSet rs = null;

try {
Class.forName("com.mysql.jdbc.Driver");
c1 = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/teacher","root", "abcde");
}
catch (Exception cnfe) {
System.out.println("Couldn't find the driver!");
System.out.println("Couldn't connect: print out a stack trace and exit.");
System.out.println("We got an exception while creating a statement:" + "that probably means we're no longer connected.");
}
try {
st = (Statement) c1.createStatement();
System.out.println("Statement Created Successfully");
} catch (SQLException se) {
System.out.println("We got an exception while creating a statement:" + "that probably means we're no longer connected.");
se.printStackTrace();
}
if (c1 != null) {
System. out.println("Hooray! We connected to the database!");
} else {
System.out.println("We should never get here.");
}
%>

<%
try{
String name=request.getParameter("username");
String abc=request.getParameter("password");

String Sql="select * from login where username='"+name+"' AND password='"+abc+"'";

c1.st.executeQuery(Sql);
{ out.println("aa");
}
catch(SQLException ex)
{
out.println(ex);
}}
%>

错误:

HTTP Status 500 -
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: 60 in the jsp file: /db conn.jsp
c1.st cannot be resolved or is not a field
57:
58: String Sql="select * from login where username='"+name+"' AND password='"+abc+"'";
59:
60: c1.st.executeQuery(Sql);
61: {
62: out.println("aa");
An error occurred at line: 63 in the jsp file: /db conn.jsp
Syntax error, insert "}" to complete Block
60: c1.st.executeQuery(Sql);
61: {
62: out.println("aa");
63: }
64:
65: catch(SQLException ex)
66: `

最佳答案

你有语法错误。尝试使用以下语法。

<% 
try{
String name=request.getParameter("username");
String abc=request.getParameter("password");

String Sql="select * from login where username='"+name+"' AND password='"+abc+"'";

c1.st.executeQuery(Sql);
out.println("aa");
}
catch(SQLException ex)
{
out.println(ex);
}
%>

关于java - 如何从 JSP 页面获取登录信息?我怎样才能更正我的jsp代码。?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38633634/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com