0

I am a beginner in spring mvc. Here is my Controller

@Controller
public class UserController {   
@RequestMapping(value="/register", method = RequestMethod.GET)
public ModelAndView registerUser(){
    User user = new User();
    user.setNickName("aaa");
    user.setId(1);
    user.setEmail("aaa@gmail.com");
    ModelAndView model = new ModelAndView("register", "model", user);
    return model;
}

And my User class

package org.proffart.bet.domain;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name="users")
public class User {
    @Id
    @Column(name="id")
    @GeneratedValue
    private Integer id;

    @Column(name="nic_name")
    private String nickName;

    @Column(name="email")
    private String email;

    @Column(name="password")
    private String password;

    @Column(name="balance")
    private Double balance;

    public String getEmail(){
        return email;
    }

    public void setEmail(String email){
        this.email = email;
    }

    public String getNickName(){
        return nickName;
    }

    public void setNickName(String nickName){
        this.nickName = nickName;
    }

    public String getPassword(){
        return password;
    }

    public void setPassword(String password){
        this.password = password;
    }

    public Double getBalance(){
        return balance;
    }

    public void setBalance(Double balance){
        this.balance = balance;
    }

    public Integer getId(){
        return id;
    }

    public void setId(int id){
        this.id = id;
    }
}

I try to display something in my jsp view (register.jsp) but can't. Please explain to me why Hello ${model.email} doesn't work in jsp. It shows me the text "Hello ${model.email}"?

Mr. Polywhirl
  • 42,981
  • 12
  • 84
  • 132
  • Is anything showing up or are you getting an error? If you're getting an error, what is it? – haley Jan 13 '15 at 20:59
  • Have you imported jsp core tags in your jsp page? – Angad Jan 13 '15 at 21:01
  • What does your JSP page look like, post that please. – Mr. Polywhirl Jan 13 '15 at 21:02
  • Yes I have imported tags <%@ page session="true" %> <%@taglib uri="http://www.springframework.org/tags" prefix="spring" %> <%@taglib uri="http://www.springframework.org/tags/form" prefix="form" %> <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> – Aram Kirakosyan Jan 13 '15 at 21:26

1 Answers1

2

There are a few things that can go wrong here, the usual suspect is the container compliance defined in the web.xml, the old JSP 1.2 has to have the directive, and you'll have to set it to

<%@ page isELIgnored="false" %>

if you're using the newer JSP version where EL is enabled by default, you should make sure that your deployment descriptor (web.xml) is at least complient to 2.4 version

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

you can find more details here and here

Community
  • 1
  • 1
Master Slave
  • 27,771
  • 4
  • 57
  • 55