Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to improve JSP with EL expression in Java backend

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces the Java back-end how to use EL expression to improve JSP related knowledge, the content is detailed and easy to understand, the operation is simple and fast, has a certain reference value, I believe that everyone after reading this Java back-end how to use EL expression to improve JSP article will have a harvest, let's take a look.

EL expression improves the shortcomings of JSPJSP

Because both HTML tags and java code can be defined within the jsp page, the following problems are caused

1. Trouble with writing: especially complex pages

2. Trouble reading

3. High complexity: operation depends on a variety of environments, JRE. JSP container (tomcat server).

4. Take up memory and disk: JSP automatically generates .java and .class files to occupy the disk, and runs .class files to occupy memory.

5. Debugging is difficult: after an error, you need to find the automatically generated .java file for debugging

6. disadvantageous team writing: front and rear staff

...

JSP has gradually retired from the stage of history, replaced by html and Ajax

Evolution process:

It's best not to write java code directly in jsp.

EL expression

Expression Language expression language for simplifying java code in JSP pages

Main function: access to data

Syntax: ${expression}

For example: ${brands}: get the data stored in the domain whose key is brands

Common problems when using Maven in idea maven is used in idea unable to create packages / classes

There is no source file, add one of these files as the source file, you can create a package or class (blue in the project structure)

Maven project that configures web in idea

Cannot create servlet in web created by maven

Deploy the tomcat plug-in in maven

Write to the pom.xml file

Org.apache.tomcat.maven tomcat7-maven-plugin 2.2 8080 / jsp-demo02 EL expression walkthrough

Create a com.web.ServletDemo1 class

Package com.web; import javax.servlet.ServletException;import javax.servlet.annotation.WebServlet;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import java.io.IOException;import java.util.ArrayList;import java.util.List; @ WebServlet ("/ demo1") public class ServletDemo1 extends HttpServlet {protected void doGet (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {/ / add data List list=new ArrayList () List.add ("zhangSan1"); list.add ("zhangSan2"); list.add ("zhangSan3"); list.add ("zhangSan4"); list.add ("zhangSan5"); System.out.println (list); / / 2, stored in the request field, which can be forwarded to the jsp page to use the EL expression request.setAttribute ("lists", list) / / 3. Forward to el-demo.jsprequest.getRequestDispatcher ("/ el-demo.jsp") .forward (request, response);}}

Create an el-demo.jsp under the web.app directory and write ${lists} in it

Insert title here$ {lists}

Running result

This is the end of the article on "how Java backend uses EL expressions to improve JSP". Thank you for reading! I believe that everyone has a certain understanding of "Java back-end how to improve JSP with EL expressions". If you want to learn more, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report