我的学校项目有问题。我使用 hibernate、jsp 和 maven 进行依赖管理。Hibernate 和 maven 工作正常,但是当我尝试使用登录屏幕制作一个简单的 jsp 页面时。它不工作。我认为问题在于 Maven 以及他如何处理项目结构,因为如果我让测试类一切正常。我无法找到有关 maven 如何与 webapps 一起使用的任何信息。
对不起我的英语错误:)。
我的项目结构:
├── src
│ └── main
│ ├── java
│ │ │
│ │ pro3
│ │ ├── model
│ │ │ ├── dao
│ │ │ │ ├── DaoInterface.java
│ │ │ │ └── HibernateDao.java
│ │ │ ├── hibernate
│ │ │ │ ├── hibernate.cfg.xml
│ │ │ │ ├── hibernate.reveng.xml
│ │ │ │ ├── HibernateUtil.java
│ │ │ │ ├── mapping
│ │ │ │ │ ├── Meal.hbm.xml
│ │ │ │ │ ├── ...
│ │ │ │ │
│ │ │ │ └── Test.java
│ │ │ └── pojo
│ │ │ ├── Meal.java
│ │ │ ├── ...
│ │ │
│ │ │
│ │ └── utils
│ │ └── LoginHandler.java
│ └── webapp
│ └── index.jsp
索引.jsp:
<jsp:useBean id="login" scope="page" class="cz.fim.pro3.utils.LoginHandler" />
...
login.verifyUser(request.getParameter("userName"), request.getParameter("password"));
登录处理程序.java:
public class LoginHandler {
DaoInterface dao = new HibernateDao();
public boolean verifyUser(String userName,String password){
return dao.verifyUser(userName, password);
}
}
HibernateDao.java:
public boolean verifyUser(String userName, String password)
在我的测试类中,当我将它作为 java 应用程序运行时,一切正常。
测试:
public static void main(String[] args) {
new Test();
LoginHandler login = new LoginHandler();
login.verifyUser("sdf", "asda");
}
pom.xml:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
</manifest>
</archive>
<webResources>
<resource>
<!-- this is relative to the pom.xml directory -->
<directory>src/main/webapp</directory>
<targetPath>/</targetPath>
<!-- enable filtering -->
<filtering>false</filtering>
</resource>
</webResources>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target> 1.7</target>
</configuration>
</plugin>
</plugins>
</build>
<packaging>war</packaging>
错误跟踪:
Stacktrace:] with root cause
java.lang.NoSuchMethodError: org.hibernate.SessionFactory.openSession()Lorg/hibernate/Session;
at cz.fim.pro3.model.dao.HibernateDao.verifyUser(HibernateDao.java:11)
at cz.fim.pro3.utils.LoginHandler.verifyUser(LoginHandler.java:11)
at org.apache.jsp.index_jsp._jspService(index_jsp.java:83)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:419)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:391)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:164)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:562)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:395)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:250)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:188)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)