qq_37611259 2017-06-01 09:15 采纳率: 0%
浏览 3011
已结题

JSP+servlet实现网页数据插入mysql问题求解

本意是将网页上表格数据插入到mysql的表中
数据获取和类的构造 L_datainsert.java
package a;

import java.io.IOException;
import java.util.Date;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public abstract class L_datainsert implements javax.servlet.Servlet {
public void doPost(HttpServletRequest request,HttpServletResponse response)
throws ServletException,IOException{
response.setContentType("text/html");
request.setCharacterEncoding("UTF-8");
String[] thi=request.getParameterValues("thi");
String[] the=request.getParameterValues("the");
String[] fl=request.getParameterValues("fl");
String[] chu=request.getParameterValues("chu");
String[] hh=request.getParameterValues("hh");
for(int n=0;n<10;n++){
Hs hs = new Hs();
hs.setThi(Double.parseDouble(thi[n]));
hs.setThe(Double.parseDouble(the[n]));
hs.setFl(Double.parseDouble(fl[n]));
hs.setChu(Double.parseDouble(chu[n]));
hs.setHh(Double.parseDouble(hh[n]));
Hsinsert db = new Hsinsert();
boolean canLogin = db.addHs(hs);}
}
}
class Hs
{
private double thi;
private double the;
private double fl;
private double chu;
private double hh;
public Hs(double i, double e, double l,double u, double h)
{
thi = i;
the = e;
fl = l;
chu = u;
hh = h;
}
public Hs()
{

}
public void setThi(double thi){
this.thi = thi;
}
public double getThi(){
return thi;
}
public void setThe(double the){
this.the = the;
}
public double getThe(){
return the;
}
public void setFl(double fl){
this.fl = fl;
}
public double getFl(){
return fl;
}
public void setChu(double chu){
this.chu = chu;
}
public double getChu(){
return chu;
}
public void setHh(double hh){
this.hh = hh;
}
public double getHh(){
return hh;
}
}
插入方法实现:Hsinsert.java
package a;
import java.sql.*;
public class Hsinsert {
boolean bInited = false;
//加载驱动
public void initJDBC() throws ClassNotFoundException {
//加载MYSQL JDBC驱动程序
Class.forName("com.mysql.jdbc.Driver");
bInited = true;
System.out.println("Success loading Mysql Driver!");
}

 public Connection getConnection() throws ClassNotFoundException,
 SQLException{
 if(!bInited){
 initJDBC();
 }
 //连接URL为 jdbc:mysql//服务器地址/数据库名
 //后面的2个参数分别是登陆用户名和密码
 Connection conn = DriverManager.getConnection(
 "jdbc:mysql://localhost:3306/login?characterEncoding=utf8&useSSL=true","root","");
 return conn;
 }

 public boolean addHs(Hs hs){
 boolean returnValue = false;
 try{
        Class.forName("com.mysql.jdbc.Driver");//加载数据库驱动,注册到驱动管理器

        Connection conn = DriverManager.getConnection(
                 "jdbc:mysql://localhost:3306/login?characterEncoding=utf8&useSSL=true","root","");
        //创建connection连接,

        String sql="insert into hs(thi,the,fl,chu,hh) values(?,?,?,?,?)";
        //添加图书信息的sql语句
        PreparedStatement ps=conn.prepareStatement(sql);
        //获取PreparedStatement
        ps.setDouble(2,hs.getThi());//对sql语句中的第1个参数赋值
        ps.setDouble(3,hs.getThe());//对sql语句中的第2个参数赋值
        ps.setDouble(4,hs.getFl());//对sql语句中的第3个参数赋值
        ps.setDouble(5,hs.getChu());//对sql语句中的第4个参数赋值
        ps.setDouble(6,hs.getHh());         
        int row=ps.executeUpdate();//执行更新操作,返回所影响的行数
        if(row>0){
            returnValue = true;
        }
        ps.close();
        conn.close();
    }catch (ClassNotFoundException e) {
     e.printStackTrace();
     }catch (SQLException e) {
     e.printStackTrace();
     }

return returnValue;
}
}
但是运行没办法实现 弹出图片说明
是因为我没有设置好xml文件吗 还是别的原因?我的xml文件内容如下:图片说明
工程内容截图为:图片说明
我重新配置了xml文件:图片说明
但还是没好,运行错误为图片说明
图片说明

  • 写回答

11条回答 默认 最新

  • qq_37611259 2017-06-01 09:12
    关注

    弹出的结果是:

    HTTP Status 404 – Not Found

    Type Status Report

    Message /login/L_datainsert

    Description The origin server did not find a current representation for the target resource or is not willing to disclose that one exists

    评论

报告相同问题?

悬赏问题

  • ¥15 一道python难题2
  • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度