<%@page import="java.sql.*"%>
<%@page import="java.util.*"%>
<%@page import="java.lang.*"%>
<%
String fname=request.getParameter("firstname");
String lname=request.getParameter("lastname");
String bday=request.getParameter("birthday");
String user="";
user = request.getParameter("username");
String pass="";
pass = request.getParameter("password");
try {
if(user.isEmpty() && pass.isEmpty()){
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/mydb", "root", "user");
String sql = "Insert into users (firstname, lastname, username, password) values('"+fname+"', '"+lname+"', '"+user+"', '"+pass+"')";
Statement stmt = conn.createStatement();
stmt.execute(sql);
conn.close();
response.sendRedirect("profile.jsp");
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
%>
<html>
<body>
<form method="post">
First Name:
<input type="text" name="firstname"/>
<br>
Last Name:
<input type = "text" name="lastname"/>
<br>
Birthdate:
Day: <select name="day">
<%
for(int x=1;x<32;x++){
%>
<option value= <% out.println(x); %> ><% out.println(x); %></option>
<%
}
%>
</select>
Month: <select name="month">
<%
for(int y=1;y<13;y++){
%>
<option value= <% out.println(y); %> ><% out.println(y); %></option>
<%
}
%>
</select>
Year: <select name="year">
<%
for(int z=1985;z<2030;z++){
%>
<option value= <% out.println(z); %> ><% out.println(z); %></option>
<%
}
%>
</select>
<br>
Username:
<input type="text" name="username"/>
<br>
Password:
<input type="password" name = "password"/>
<br>
<input type="submit" value="Register"/>
</form>
</body>
</html>
我得到错误:
HTTP 状态 500 -
类型异常报告
信息
描述服务器遇到一个内部错误 () 阻止它完成这个请求。
例外
org.apache.jasper.JasperException:java.lang.NullPointerException 根本原因
java.lang.NullPointerException