Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/372.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 我不知道为什么jsp文件中的这个简单代码会出错_Java_Html_Jsp - Fatal编程技术网

Java 我不知道为什么jsp文件中的这个简单代码会出错

Java 我不知道为什么jsp文件中的这个简单代码会出错,java,html,jsp,Java,Html,Jsp,我试过几种方法使它起作用,但我似乎无法解决问题。这一部分决定登录是否成功,错误在登录成功的部分,它输出并发布用户名供下一页使用。错误具体发生在这一行编辑上:该行在发布道歉时由于某种原因被切断。我还添加了完整的代码,不要介意明显的安全问题,它对我的工作并不重要 <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <%@ page i

我试过几种方法使它起作用,但我似乎无法解决问题。这一部分决定登录是否成功,错误在登录成功的部分,它输出并发布用户名供下一页使用。错误具体发生在这一行编辑上:该行在发布道歉时由于某种原因被切断。我还添加了完整的代码,不要介意明显的安全问题,它对我的工作并不重要

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ page import="java.sql.*"%>
<%@ page import="javax.sql.*"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
    <%
        //user variable declarations
        String idnum = "";
        String pwd = "";

        String user = request.getParameter("user");
        String password = request.getParameter("pwd");
        Class.forName("com.mysql.jdbc.Driver");
        java.sql.Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/assignment2", "root",
                "1234");
        Statement stmt = conn.createStatement();
        String query = "SELECT * from users where idnum = '" + user + "'";
        //out.println("Query: "+query);
        ResultSet rs = stmt.executeQuery(query);

        //get idnum and password for checks
        while (rs.next()) {
            idnum = rs.getString("idnum");
        }
        query = "SELECT * from users where idnum = '" + user + "'";
        rs = stmt.executeQuery(query);
        while (rs.next()) {
            pwd = rs.getString("password");
        }
        if (pwd.equals(password)) {
    %>
    </br>Welcome 
    <form action="BuyTicket.jsp" method="post">
        <%=out.print(idnum)%>
        <input type="submit" text="Buy Tickets" />
    </form>

    </br>
    <%
        } else {
    %>
    </br>Invalid Username or Password please try one of the following
    </br>
    <a href="Login.html">Login</a>
    </br>
    <a href="Register.html">Register</a>
    </br>
    <%
        }
    %>
    <a href="index.html">Home</a>
</body>
</html>

你没有空缺,我很困惑。这是PHP还是Java?好吧,你删掉了有用的信息,让我们看看错误在哪一行。。。既然你可以复制并粘贴文本,为什么还要发布一个截图呢?不知道那是什么,但是,从纯逻辑上讲,任何%>都不应该与标题“its a jsp”中的开头@spork its搭配使用。代码部分是jsp中的java。@LowKeyEnergy对由于某种原因在发布时被切断表示歉意。我把这行代码放回原处,因为它是代码的一个片段。我可以发布整个代码,如果这会更有帮助的话。它具有jsp所需的所有标记,只是java代码不起作用。请确保您可以发布它。基本上,您需要平衡所有scriplet标记,当您想要编写java代码时,它必须在标记之间进行。添加了所有代码我认为您不需要out.print在您有out.printidnum的地方打印。printidnum是一个JSP表达式,它会打印到输出中,所以您应该能够这样做。我没有意识到这是可行的,谢谢
<%=out.print(idnum)%>
<%
    if (pwd.equals(password)) {
%>
    </br>Welcome 
    <form action="BuyTicket.jsp" method="post">
        <%=out.print(idnum)%>
        <input type="submit" text="Buy Tickets" />
    </form>

    </br>
<%
    } else {
%>
    </br>Invalid Username or Password please try one of the following
    </br>
    <a href="Login.html">Login</a>
    </br>
    <a href="Register.html">Register</a>
    </br>
<%
    }
%>