专业财税服务推荐

精选优质财税服务,为企业提供专业、可靠的财税解决方案,助力企业健康发展

零报税代理记账
零申报代理记账
报税做账算帐财务报表老会计做账
代理记账
咨询微信:lhy_happyday
工商营业执照年度年报年检公示
全国个体、企业、公司、合作社工商年审年报服务!
个体/10元/次 企业/20元/次
咨询微信:lhy_happyday
财税咨询服务
一对一专业财税咨询,解决企业财税难题,提供定制方案
咨询微信:lhy_happyday
财务分析服务
小规模个体报税0申报税务年报工商年报月报季报报税代理记账
咨询微信:lhy_happyday
立即咨询专业财税顾问
微信号: lhy_happyday
会计从业9年,管理多家个体工商、小规模、一般纳税人等企业的财务、税务等相关工作!。
扫码或搜索添加微信,备注"财税咨询"获取专属优惠
知方号 知方号

What is JSP? Introduction to Jakarta Server Pages javaserver pages api

Layout of a JSP web application

Tomcat follows the standard layout for Java servlet and JSP pages. The general structure is a folder with the name of the application, which is deployed inside Tomcat’s /webapps directory.

In the Implicit Objects application, the application is /examples. Opening that folder reveals three important children: the /WEB-INF directory, the index.html file, and a set of other directories.

The WEB-INF directory contains metadata that informs Tomcat how to run the application.

The remaining content, including index.html, is directly accessible, just as it would be in a typical web server. Likewise, the implicit-objects.jsp is available to view, and is automatically handled as a JSP page (not an HTML page) by the server.

JSP’s request-response architecture

In a typical servlet/JSP application, servlets receive requests and interact with server-side components and services (such as the database) to fulfill them. Once handled, the request result is forwarded to a JSP page, which presents the response based on the data.

A servlet uses the following syntax when sending a request response to a JSP page:

request.getRequestDispatcher("path/to/jsp.jsp").forward(req,res);

Whatever data the servlet has inserted into the various JSP scopes will be accessible to JSP as objects, like the param object you saw earlier. A scope is simply a range of life for a given object. Request and response objects are request scoped, meaning they live for the duration of the request. Other scopes include page scope (living as long as the JSP page does) and session scope (terminating when the user ends the given session).

MVC in JSP and servlet applications

The interaction between servlets and JSP pages follows the classic MVC pattern: the controller object (a servlet) prepares the model object (an item or user object) and sends it to the view (the JSP page) for rendering. MVC’s clean separation of concerns has made it a popular and long-lived approach to building software. Struts is one of the oldest and most well-known frameworks implementing MVC with JSP and servlets. Spring MVC also includes built-in support for JSP.

Using Spring MVC is probably the most common approach to JSP development within a larger framework, since it gives you access to the entire Spring ecosystem. A good way to accelerate the process is use a JSP Spring Boot template.

Conclusion

JSP is a well-known and versatile technology for developing Java web application views. Combined with servlets, JSP pages are very powerful and provide access to the entire range of Java capabilities. While Jakarta Server Pages may not be your first choice for developing a modern Java web application, you will encounter JSP pages in legacy applications. It’s also a good choice for simpler applications, where you want to quickly connect your HTML front end to server-side Java code. The JSTL tags are capable of handling most web application requirements, and third-party libraries extend that functionality for specific technologies and use cases.

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至lizi9903@foxmail.com举报,一经查实,本站将立刻删除。