[英]Why we can not access request from jsp declarations?
I am new to the JSP related technologies. 我是JSP相关技术的新手。 I faced a strange situation: works find with scriplet
我遇到了一个奇怪的情况:使用Scriplet查找作品
<%
String username = request.getParameter("username");
if ( username != null && username.length() > 0 ) {
}
%>
But with declaration request object can not be found? 但是带有声明的请求对象找不到吗?
I read that when be define method or variable in declarations they are part of the servlet, from the servlet we can access request object. 我读到,当在声明中使用define方法或变量时,它们是servlet的一部分,从servlet中我们可以访问请求对象。 So why is this strange behavior?
那么,为什么这种奇怪的行为呢?
JSP is converted into a servlet before compilation. 在编译之前,JSP将转换为servlet。
What you write inside a jsp scriptlet go inside the service() method of the servlet and everything inside jsp declaration go outside service method but inside servlet class. 您在jsp脚本中编写的内容放在servlet的service()方法中,而jsp声明中的所有内容都放在service方法之外,而在servlet类中。
if condition can only be used inside methods and request is a parameter of service method So it cannot be accessed outside service method. 如果条件只能在方法内部使用,而请求是服务方法的参数,则不能在服务方法外部访问它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.