**HTTP Status 500 - An exception occurred processing JSP page /reg.jsp at line 24
type Exception report
message An exception occurred processing JSP page /reg.jsp at line 24
description The server encountered an internal error that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: An exception occurred processing JSP page /reg.jsp at line 24
22: Statement st= con.createStatement();
23: ResultSet rs;
24: int i = st.executeUpdate("INSERT INTO userinfo" +
25: " (userid, fname, lname, email, pwd)" +
26: " VALUES" +
27: " ('" + userid+ "'," +
**
表:userinfo
Columns:
userid int(11) AI PK
fname varchar(45)
lname varchar(45)
pwd varchar(45)
email varchar(45)*
网页内容
WEB_INF
reg.jsp**
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>regjsp</title>
</head>
<body>
<form action="MyApp" >
<%@ page import ="java.sql.*" %>
<%@ page import ="javax.sql.*" %>
<%
String userid=request.getParameter("userid");
String pwd=request.getParameter("pwd");
String fname=request.getParameter("fname");
String lname=request.getParameter("lname");
String email=request.getParameter("email");
Class.forName("com.mysql.jdbc.Driver");
java.sql.Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/demo",
"root","mupurili123A");
Statement st= con.createStatement();
ResultSet rs;
int i = st.executeUpdate("INSERT INTO userinfo" +
" (userid, fname, lname, email, pwd)" +
" VALUES" +
" ('" + userid+ "'," +
" '" + fname + "'," +
" '" + lname + "'," +
" '" + email + "','" +pwd + "')");
if (i > 0) {
session.setAttribute("userid", userid);
//response.sendRedirect("welcome.jsp");
out.print("Registration Successfull!"+"<a href='login.jsp'>Go to Login</a>");
} else {
out.print("Registration failed!");
//response.sendRedirect("index.html");
}
%>
<a href ="Login.html">Login</a><br/><br/>
<a href="index.html">Home</a>
</form>
</body>
</html>
Java资源 SRC
package com.srk.pkg;
import java.sql.DriverManager;
import java.sql.ResultSet;
import com.mysql.jdbc.Connection;
import com.mysql.jdbc.Statement;
public class Conn {
public static void main(String[] args){
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/demo",
"root","mupurili123A");
Statement st= (Statement) con.createStatement();
ResultSet rs=st.executeQuery("select *from demo");
while(rs.next()){
System.out.println(rs.getInt(1)+" "+rs.getString(2)+" "+rs.getString(3));
con.close();
}
}catch (Exception e){
System.out.println(e);
}
}
}
答案 0 :(得分:-1)
而不是传递String
userid
,而int
期望数据库中的原始数据类型Integer.parseInt()
抛出意外情况,导致其无法完成请求。您可以使用{{1将String转换为int。
String userid=request.getParameter("userid");
int id=Integer.parseInt(userid);
并在您的查询中将userid
替换为id
,并确保mysql-connector-java-version.jar
中有tomcat_dir/lib/
。