How to assemble templates (EL technology related)?
ringa_lee
ringa_lee 2017-05-27 17:40:58
0
1
690

As the title says, I have a page template in the background, which contains some places where specific data needs to be filled in. I call a method to pass in the template file and context object, and then return an assembled page html code. May I ask what technology is more convenient to implement this? I have considered Spring's EL expression and Java EE's JSTL, but I think it is not very useful. It would be best if you could give me a simple example.

template:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Spring EL Test</title>
</head>
<body>
    Hello, ${user.name}!
</body>
</html>

It is possible to call such a method

String result = parse(File file, Object contextObj);    // 得到组装后数据

Data after assembly:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Spring EL Test</title>
</head>
<body>
    Hello, ZhangSan!
</body>
</html>
ringa_lee
ringa_lee

ringa_lee

reply all(1)
大家讲道理

First of all, let me correct you. EL expressions are not provided by Spring, but by JSP 2.x.

The so-called assembly means using request.setAttribute()设一个名为user objects to parse the objects in jsp.

This should be enough:

User user = new User("ZhangSan"); // user.getName() 应该得到"ZhangSan"
request.setAttribute("user", user);
// 然后是forward到这个jsp
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template