哦糟了 2020-12-03 13:47 采纳率: 100%
浏览 85
已结题

报错:HTTP Status 500 – Internal Server Error

用的druid连接池,5.7.31的mysql,8.5.60的tomcat,1.8的Jdk.数据库部分User,UserDao和JDBCUtil写完测试了,功能可以。Servlet啥功能也没有的时候是可以访问的,但是一旦用到UserDao的功能就报错。查了很多事jar包目录的问题,我的jar包就在WEB-INF目录下实在找不出原因了。多谢有缘人。

报错页面:

出错部分:

UserDao ud = new UserDao();
User user = ud.Login(loginuser);

全部代码:

package com.xupt.domain;

public class User {
    private int id;
    private String username;
    private String password;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    @Override
    public String toString() {
        return "User{" +
                "id=" + id +
                ", username='" + username + '\'' +
                ", password='" + password + '\'' +
                '}';
    }
}


import org.springframework.jdbc.core.JdbcTemplate;

public class UserDao {
    private JdbcTemplate template = new JdbcTemplate(JDBCUtil.getDataSource());

    public User Login(User loginuser){
        String sql = "select * from useraccount where username = 'liu' and password = '123456'";

        /*User user = template.queryForObject(sql,
                new BeanPropertyRowMapper<User>(User.class),
                loginuser.getUsername(),loginuser.getPassword());*/
        User user = template.queryForObject(sql,new BeanPropertyRowMapper<User>(User.class));

        return user;
    }
}


package com.xupt.Util;

import com.alibaba.druid.pool.DruidDataSourceFactory;
import com.sun.corba.se.spi.orbutil.fsm.Input;

import javax.sql.DataSource;
import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Properties;

public class JDBCUtil {
    private static DataSource ds;

    static {
        try {
            Properties pro = new Properties();

            InputStream is = JDBCUtil.class.getClassLoader().getResourceAsStream("druid.properties");

            pro.load(is);

            ds = DruidDataSourceFactory.createDataSource(pro);
        } catch (IOException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static DataSource getDataSource(){
        return ds;
    }

    public static Connection getConnection() throws SQLException {
        return ds.getConnection();
    }
}


package com.xupt.servlet;

import com.xupt.dao.UserDao;
import com.xupt.domain.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/ServletLogin")
public class ServletLogin extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("hello");
        String username = "liu";
        String password = "123456";

        User loginuser = new User();
        loginuser.setUsername("username");
        loginuser.setPassword("password");

        UserDao ud = new UserDao();
        User user = ud.Login(loginuser);
        System.out.println(user);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}

  • 写回答

22条回答 默认 最新

  • benpaodexin_l 2020-12-04 10:11
    关注

    你jar包截图发出来看看

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(21条)

报告相同问题?

悬赏问题

  • ¥45 工程软件单片机设计课题要求
  • ¥15 在centos7安装conda
  • ¥15 c#调用yolo3 dll文件获取的数据对不上
  • ¥20 WPF 如何实现多语言,label 和cs(live Charts)中是否都能翻译
  • ¥15 STM32F103上电短路问题
  • ¥15 关于#单片机#的问题:以ATMEGA128或相近型号单片机为控制器设计直流电机调速的闭环控制系统(相关搜索:设计报告|软件设计|流程图)
  • ¥15 打开软件提示错误:failed to get wglChoosePixelFormatARB
  • ¥15 (标签-python|关键词-char)
  • ¥15 python+selenium,在新增时弹出了一个输入框
  • ¥15 苹果验机结果的api接口哪里有??单次调用1毛钱及以下。