Scriptlet将任意代码插入到servlet的_jspService方法中 [英] Scriptlets inserts arbitrary code into servlet's _jspService method

查看:269
本文介绍了Scriptlet将任意代码插入到servlet的_jspService方法中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


Scriptlets允许您将任意代码插入到servlet的_jspService方法中。

任何人都可以用包含代码块的示例来解释这个语句吗?

Can anyone explain this statement with an example containing a block of code?

我知道JSP和Servlets的语法内容,我需要知道的是

I am aware about syntactical stuff of JSP and Servlets, what I need to know is


  • 在什么情况下使用任意代码

  • In what context arbitrary code is used?

_jspService()是一个JSP生命周期的方法,然后,

_jspService() is a method of JSP life cycle then,


  • servlet是什么意思方法

  • What does it mean by servlet's method?

推荐答案

事实上,JSP已被容器转换为扩展HttpServlet的Java类,然后该类就像手工编码的servlet一样被编译和执行。

A JSP is in fact transformed by the container into a Java class extending HttpServlet, that class is then compiled and executed exactly as a hand-coded servlet would be.

你在JSP中的代码被转换成Java代码构成生成的servlet的_jspService方法。所以,例如

The code you have into the JSP is transformed into Java code that constitutes the _jspService method of the generated servlet. So, for example

<html>
<% String foo = "hello"; out.println(foo); %>

由容器转换为类似

void _jspService(JspWriter out) {
    out.println("<html>");
    String foo = "hello"; out.println(foo);
}

所以,无论你写入scriptlet的代码是什么(任意代码)最终在容器从JSP创建的servlet的_jspService方法中。

So, whatever code you write into your scriptlets (arbitrary code) ends up in the _jspService method of the servlet created by the container from the JSP.

这篇关于Scriptlet将任意代码插入到servlet的_jspService方法中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆