能谈谈对下面一段话的理解吗??(高分求解)

joards 2002-07-02 10:46:20
“声明变量和方法可以放在Scriptlet 中,它和把两者放到<%!……%>中的区别是,前者中的声明语句在编译为Servlet 的时候将作为类的属性存在,而放在Scriplet 中的声明将在类 的方法内部被声明。”

我不是很明白,能解释清楚的就给分!!
...全文
35 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
shuohua 2002-07-03
  • 打赏
  • 举报
回复
哦,虽然不能帮你,但是帮你UP一下!希望你能得到好的解答!
UP! :)
joards 2002-07-03
  • 打赏
  • 举报
回复
jicco(凌风) :谢谢给我文字纠错,一定给你10分
joards 2002-07-03
  • 打赏
  • 举报
回复
这是一种情况,那在scriptlet中包含的呢,是不是就转换成 service 的内部方法和变量了呢??
saucer 2002-07-03
  • 打赏
  • 举报
回复
I think it should be
声明变量和方法可以放在Scriptlet 中,它和把两者放到<%!……%>中的区别是,前者中的声明语句在编译为Servlet 的时候将在类的方法内部被声明,而放在<%!……%> 中的声明将作为类的属性存在。”

here is an example:

testvar.jsp:
this one has no !....
<%int i;%>
this one has !
<%! int j;%>


it is translated into testvar$jsp.java as in TOMCAT:
package org.apache.jsp;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.jsp.*;
import org.apache.jasper.runtime.*;


public class testvar$jsp extends HttpJspBase {

// begin [file="/jsp/testvar.jsp";from=(3,3);to=(3,10)]
int j; //<**************************HERE
// end

static {
}
public testvar$jsp( ) {
}

private static boolean _jspx_inited = false;

public final void _jspx_init() throws org.apache.jasper.runtime.JspException {
}

public void _jspService(HttpServletRequest request, HttpServletResponse response)
throws java.io.IOException, ServletException {

JspFactory _jspxFactory = null;
PageContext pageContext = null;
HttpSession session = null;
ServletContext application = null;
ServletConfig config = null;
JspWriter out = null;
Object page = this;
String _value = null;
try {

if (_jspx_inited == false) {
synchronized (this) {
if (_jspx_inited == false) {
_jspx_init();
_jspx_inited = true;
}
}
}
_jspxFactory = JspFactory.getDefaultFactory();
response.setContentType("text/html;charset=ISO-8859-1");
pageContext = _jspxFactory.getPageContext(this, request, response,
"", true, 8192, true);

application = pageContext.getServletContext();
config = pageContext.getServletConfig();
session = pageContext.getSession();
out = pageContext.getOut();

// HTML // begin [file="/jsp/testvar.jsp";from=(0,0);to=(1,0)]
out.write("this one has no !....\r\n");

// end
// begin [file="/jsp/testvar.jsp";from=(1,2);to=(1,8)]
int i; //<**************************HERE
// end
// HTML // begin [file="/jsp/testvar.jsp";from=(1,10);to=(3,0)]
out.write("\r\nthis one has !\r\n");

// end
// HTML // begin [file="/jsp/testvar.jsp";from=(3,12);to=(4,0)]
out.write("\r\n");

// end

} catch (Throwable t) {
if (out != null && out.getBufferSize() != 0)
out.clearBuffer();
if (pageContext != null) pageContext.handlePageException(t);
} finally {
if (_jspxFactory != null) _jspxFactory.releasePageContext(pageContext);
}
}
}
jicco 2002-07-03
  • 打赏
  • 举报
回复
应该是
“声明变量和方法可以放在Scriptlet 中,它和把两者放到<%!……%>中的区别是,前者中的声明语句在编译为Servlet 的时候将作为类的属性存在,而放在<%!……%>中的声明将在类 的方法内部被声明。”

81,091

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧