我收到一些错误,因为 404 未找到错误,请帮助我。未找到使用 jsp HTTP 状态 404 在 mysql 中插入图像.我正在尝试在 mysql 数据库中插入图像,并且我使用了 mysql jdbc 驱动程序。
在索引中.jsp
<%--
Document : index
Created on : 23-Jan-2017, 11:51:34
Author : AshwinKArki
--%>
<%@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>
<form name="f1" method="post" action="main">
Select file:<input type="file" name="file1" >
<input type="submit" value="insert" />
</form>
</body>
</html>
in 主.jsp : 另一个页面
<%@page import="java.sql.*" %>
<%@page import="java.io.*" %>
<%
String file2=request.getParameter("file1");
try{
Class.forName("com.mysql.jdbc.Driver");
Connection conn=DriverManager.getConnection("jdbc:mysql://localhost/storefile");
String sql="INSERT INTO tbl_image VALUES (?)";
PreparedStatement stmt=conn.prepareStatement(sql);
stmt.setString(1,file2);
stmt.executeUpdate();
out.print("Suucesfull");
stmt.close();
conn.close();
}catch(Exception e){
out.print(e.getMessage());
}
%>
*
你没有转发到正确的动作,因为你的动作是一个jsp文件,所以你也应该设置扩展名,不像servlet那样,当你只设置文件名时,所以必须有:action="main.jsp"
而不是action="main"
<form name="f1" method="post" action="main.jsp">
Select file:<input type="file" name="file1" >
<input type="submit" value="insert" />
</form>