Reputation: 41
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("[email protected]");
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}"?
Upvotes: 0
Views: 579
Reputation: 28519
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
Upvotes: 2