<form action="register.jsp" method="post">
id:<input type="text" name="id"/><br><br/>
Name:<input type="text" name="name"/><br><br/>
Password:<input type="password" name="password"/><br><br/>
Email ID:<input type="text" name="email"/><br><br/>
<input type="submit" value="register"/>
</form>
上面的文件是 index.jsp
<%@page import="com.javatpoint.mypack.UserDao"%>
<jsp:useBean id="obj" class="com.javatpoint.mypack.User"></jsp:useBean>
<jsp:setProperty property="*" name="obj"/>
<%
obj.setName(request.getParameter("name"));
obj.setPassword(request.getParameter("password"));
obj.setEmail(request.getParameter("email"));
try
{
System.out.println("--------->"+obj.getName());
int i=UserDao.register(obj);
if(i>0)
{
out.print("You are successfully registered");
}
else
{
out.print("registration failed");
}
}
catch(Exception e)
{
out.print("You are not registered");
}
%>
上面的文件是 register.jsp
package com.javatpoint.mypack;
public class User {
public int id;
public String name,password,email;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
}
上面的文件是user.java
package com.javatpoint.mypack;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.cfg.*;
public class UserDao {
public static int register(User u){
int i=0;
try{
Session session=new Configuration().configure().buildSessionFactory().openSession();
Transaction t=session.beginTransaction();
t.begin();
i=(Integer)session.save(u);
t.commit();
session.close();
}catch (Exception e) {
e.printStackTrace();
}
return i;
}
}
上面的程序是 UserDao.java 在执行应用程序时它是 hibernate.properties not found 错误请回复我为什么会发生