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