简体   繁体   English

为什么我无法使用Spring MVC和Hibernate在JSP页面中显示数据库值

[英]Why I am unable to display database values in jsp page , using spring mvc and hibernate

Any one can help me...?? 任何人都可以帮助我... ?? Actually I am unable to display my database values in the jsp page...! 实际上,我无法在jsp页面中显示我的数据库值...! Here I am sharing all my code...!! 在这里,我分享了我所有的代码...! Please find it and help me....I am doing well. 请找到它并帮助我....我很好。 actually it not gives any error. 实际上它没有任何错误。 so i am too much confuse. 所以我太困惑了。 so anyone can help me...Please. 这样任何人都可以帮助我...请。 Thank You. 谢谢。

My Dao Class is look as 我的道课是

package com.mvn.blog.dao;

import java.util.ArrayList;
import java.util.List;

import javax.transaction.Transactional;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.mvn.blog.domain.UserDomain;
import com.mvn.blog.dto.UserDto;
import com.mvn.blog.utility.CommonUtils;

@Repository
public class UserDaoImpl implements IUserDao {

    @Autowired
    SessionFactory sessionFactory;

    public void setSessionFactory(SessionFactory sf) {
          this.sessionFactory = sf;

    }

    @Transactional
    public Boolean saveUser(UserDto userDto) throws Exception {
        Session session = this.sessionFactory.getCurrentSession();
        boolean result= false;
        UserDomain user = CommonUtils.convertObject(userDto, UserDomain.class);

        session.save(user);
        result = true;
        return result;
    }

    @Transactional
    public List<UserDto> getUserList() throws Exception {
        List<UserDto> userList = new ArrayList<UserDto>();
        Session session = this.sessionFactory.getCurrentSession();
        Criteria user = session.createCriteria(UserDomain.class);

        List<UserDomain> result = user.list();
        //System.out.println(result);
        for(UserDomain userDomain : result){
            UserDto userDto = CommonUtils.convertObject(userDomain, UserDto.class);
            userList.add(userDto);      
            }
        //System.out.println(userList);

        return userList;
    }

    }

}

My controllerClass 我的控制器类

package com.mvn.blog.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.mvn.blog.domain.UserDomain;
import com.mvn.blog.dto.UserDto;
import com.mvn.blog.service.IUserMaintenance;
import com.mvn.blog.utility.CommonUtils;

@Controller
public class HomeController {


    @Autowired
    IUserMaintenance userMaintenance;


    @RequestMapping("/home")
    public String home(){
        return "index";
    }

    @RequestMapping(value = "/userlist" , method = RequestMethod.GET)
    public ModelAndView  getUserList() throws Exception{
        List<UserDto> userList = userMaintenance.getUserList();
        //System.out.println(userList);

        for(UserDto users : userList){
            System.out.println(users.getUsername()+" "+ users.getEmail()+" "+users.getPassword());

        }

        return new  ModelAndView("viewuser", "userList" , userList);
}

}





My Jsp File


<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>

<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%> 
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>   
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<body>
<h2>User List</h2>  
<table border="2">  
<tr><th>Name</th><th>Email</th><th>Password</th><th>Edit</th><th>Delete</th></tr>  
   <c:forEach items="${userList}" var="user">   
   <tr>  
   <td><c:out value="${user.username}"/></td>  
   <td><c:out value="${user.email}"/></td>  
   <td><c:out value="${user.password}"/></td>  
   <td><a href="edituser/${user.userid}">Edit</a></td>  
   <td><a href="deleteuser/${user.userid}">Delete</a></td>  
   </tr>  
   </c:forEach>  
   </table>  
   <br/> 

</body>
</html>

This is bcoz you are using the old JSP 1.2 descriptor, defined by DTD. 这是您正在使用DTD定义的旧JSP 1.2描述符的bcoz。
The EL is disabled or ignored by default, you have to enable it manually. 默认情况下,禁用或忽略EL,您必须手动启用它。
use the standard JSP 2.0 or above descriptor, defined by w3c schema. 使用w3c模式定义的标准JSP 2.0或更高版本的描述符。

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns="http://java.sun.com/xml/ns/javaee" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" 
    id="WebApp_ID" version="3.0">
/...
</web-app>

Have a look at this reference 看看这个参考

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用Hibernate和Spring MVC从数据库在Jsp页面上显示图像 - How to display image on Jsp page from database using Hibernate and spring MVC Spring MVC: - 当用户选择图像时,如何让上传的图像显示在jsp页面上。我在这里使用Spring Framwework - Spring MVC :- How do i get the uploaded image to display on jsp page as soon as the user selects the image.I am using Spring Framwework here 使用JSP Spring MVC Hibernate从数据库动态创建复选框 - Dynamically create checkbox from database using jsp spring mvc hibernate 无法使用Spring MVC在JSP中显示上传的图像(保存在文件系统中以及数据库中的存储位置,例如C:\\ Database \\ ..) - Unable to display uploaded image (saved in file system and stored location on database eg., C:\Database\.. ) in jsp using spring mvc 如何使用Spring MVC将值JSP页面传递到Java中? - how to pass values jsp page into java using spring mvc? 使用Spring MVC和Hibernate无法从Oracle数据库检索图像 - Unable to retrieve image from oracle database using spring mvc and hibernate Spring MVC +休眠+ JSP - Spring MVC + Hibernate + JSP 使用Spring MVC在JSP页面中显示一组对象 - Display a Set of Objects in JSP page, with Spring MVC 如何使用java类在jsp页面中显示数据库中的值? - How to display values from database in jsp page using java class?? 将数据库值传递给Spring MVC中的jsp - Pass the database values to jsp in Spring MVC
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM