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

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 consideredSpring's EL expressionandJava EE's JSTL, but I think it is not very useful. It would be best if you could give me a simple example.

template:

    Spring EL Test 
Hello, ${user.name}!

It is possible to call such a method

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

Data after assembly:

    Spring EL Test 
Hello, ZhangSan!
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 usingrequest.setAttribute()设一个名为userobjects 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
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!