java - Retrieving data from database using jsp (Hibernate + Spring + Maven) -


hello, guys. i'm trying retrieve data oracle database, nothing appears on screen.

here 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> 

it seems ok. , here spring controller userscontroller.java

package com.controller; import com.database.users; import com.service.usersmanager; import java.util.list; import org.apache.log4j.logger; import org.springframework.beans.factory.annotation.autowired; import org.springframework.stereotype.controller; import org.springframework.ui.model; import org.springframework.web.bind.annotation.requestmapping; import org.springframework.web.bind.annotation.requestmethod;  /**  *  * @author glebk  */ @controller @requestmapping("/users") public class userscontroller {      private static final logger log = logger.getlogger(userscontroller.class);      @autowired     usersmanager manager;      @requestmapping(value = "/getusers", method = requestmethod.get)     public string getallemployees(model model)     {         list<users> users = manager.getallusers();         model.addattribute("users", users);         return "userslist";     } } 

my 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> 

and event-servlet.xml

<?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> 

when try put message model, displayed. attribute "users" there nothing. please, me. thanks.

i found out answer. replaced

 <c:foreach items="${users}" var="user">        <tr>            <td>${user.userid}</td>            <td>${user.login}</td>        </tr>  </c:foreach> 

with

<c:foreach items="${users}" var="user">       <tr>           <td>               <c:out value="${user.userid}"/>           </td>           <td>               <c:out value="${user.login}" />          </td>      </tr> </c:foreach> 

and works!


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -