Java 使用jsp从数据库检索数据(Hibernate+;Spring+;Maven)
大家好。我试图从Oracle数据库检索数据,但屏幕上没有显示任何内容 这是我的Java 使用jsp从数据库检索数据(Hibernate+;Spring+;Maven),java,spring,hibernate,maven,jsp,Java,Spring,Hibernate,Maven,Jsp,大家好。我试图从Oracle数据库检索数据,但屏幕上没有显示任何内容 这是我的usersList.jsp <%@page contentType="text/html" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <title>Spring MVC Hello World</title> </head> <body> &l
usersList.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<title>Spring MVC Hello World</title>
</head>
<body>
<h2>All Users in System</h2>
<table border="1">
<tr>
<th>User Id</th>
<th>Login</th>
</tr>
<c:forEach items="${users}" var="user">
<tr>
<td>${user.userId}</td>
<td>${user.login}</td>
</tr>
</c:forEach>
</table>
</body>
</html>
我的web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<servlet>
<servlet-name>event</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>event</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.1.xsd
">
<tx:annotation-driven />
<context:component-scan base-package="com" />
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"></property>
<property name="url" value="jdbc:oracle:thin:@localhost:1521:xe"></property>
<property name="username" value="admin"></property>
<property name="password" value="0000"></property>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="configLocation">
<value>
classpath:hibernate.cfg.xml
</value>
</property>
<property name = "dataSource" ref = "dataSource"></property>
</bean>
<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" />
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/views/" />
<property name="suffix" value=".jsp" />
</bean>
<bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
</beans>
当我尝试将一些消息放入模型时,它会显示出来。但有了“用户”属性,就什么都没有了。
请帮帮我。
谢谢 试着像这样编写组件扫描:
<context:component-scan base-package="com.controller" />
我找到了答案。我刚换了
<c:forEach items="${users}" var="user">
<tr>
<td>${user.userId}</td>
<td>${user.login}</td>
</tr>
</c:forEach>
${user.userId}
${user.login}
与
而且它有效 您使用哪个url?发布您的we.xml和spring.xml配置localhost:8081/Event-1.0/users/getUsers它可以工作,但没有数据。只有一个空表。bean在哪里:manager@Autowired用户管理器;您是如何实现UserManager.java的,您没有看到任何异常。它是否真的从数据库中检索到任何数据。我在文件event-servlet.xml或任何地方都看不到自动连线bean
<c:forEach items="${users}" var="user">
<tr>
<td>${user.userId}</td>
<td>${user.login}</td>
</tr>
</c:forEach>
<c:forEach items="${users}" var="user">
<tr>
<td>
<c:out value="${user.userId}"/>
</td>
<td>
<c:out value="${user.login}" />
</td>
</tr>
</c:forEach>