мой код такой, как показано ниже
Для моего HTML У меня есть форма, которая использует метод get.
Код: Выделить всё
form action="PlaylistServlet" method="get">
Код: Выделить всё
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
Users user1 = new Users();
String userName = request.getParameter("userName");
String password = request.getParameter("password");
SetData sd = new SetData();
Users us = sd.get(userName); //get method in service class. Line 38
String passwordDB = us.getPassword();// line 39
if (user1.checkPassword(password, passwordDB)) {
response.sendRedirect("UserLogin.html");
}
}
Код: Выделить всё
public Users get(String userName) {
Users us = null;
SessionFactory sf = null;
Session session1 = null;
try {
sf = new Configuration().configure("/hibernate.cfg.xml").buildSessionFactory();
session1 = sf.openSession();
Transaction tx = session1.beginTransaction();
us = (Users) session1.get(Users.class,userName); // line 64
tx.commit();
session1.close();
} catch (Exception e) {
e.printStackTrace();
} finally {
sf.close();
}
return us;
}
Код: Выделить всё
java.lang.IllegalArgumentException: id to load is required for loading
at com.marv.service.SetData.get(SetData.java:64)
at com.marv.service.PlaylistServlet.doGet(PlaylistServlet.java:38)
java.lang.NullPointerException
at com.marv.service.PlaylistServlet.doGet(PlaylistServlet.java:39)
Подробнее здесь: https://stackoverflow.com/questions/332 ... d-password