gpt4 book ai didi

java - Spring MVC View - 解析占位符

转载 作者:行者123 更新时间:2023-12-02 05:04:21 24 4
gpt4 key购买 nike

我是 spring mvc 的初学者。这是我的 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;
}

还有我的用户类

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;
}
}

我尝试在 jsp View (register.jsp) 中显示某些内容,但不能。请向我解释为什么 Hello ${model.email} 在 jsp 中不起作用。它向我显示文本“Hello ${model.email}”?

最佳答案

这里可能会出现一些问题,通常的怀疑是 web.xml 中定义的容器合规性,旧的 JSP 1.2 必须有该指令,并且您必须将其设置为

<%@ page isELIgnored="false" %>

如果您使用的是默认启用 EL 的较新 JSP 版本,则应确保您的部署描述符 (web.xml) 至少兼容 2.4 版本

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

您可以找到更多详情herehere

关于java - Spring MVC View - 解析占位符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27931204/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com