简体   繁体   English

为什么我们不能从jsp声明访问请求?

[英]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.

相关问题 在jsp中上传文件后,为什么无法从请求中访问参数? - Why I can't get access to parameters from a request after upload a file in jsp? 在将请求从 servlet 发送到 jsp 后,我们能否以某种方式更改地址栏中的 url - Can we somehow change the url in addressbar after dispatching request from servlet to jsp 为什么我们可以从外部类访问内部类中的变量? - Why can we access a variable in an inner class from an outer class? Java:为什么我们可以从非子类访问字段和方法时需要扩展类 - Java: why we need to extend a class when we can access the fields and methods from non sub class 我们可以使用JavaScript Function从JSP调用Servlet吗? - Can we call Servlet from JSP using JavaScript Function? 我们可以在jsp中实现一个接口吗? - Can we implement an interface in jsp? 为什么我不能访问jsp中的字段值(它返回null)? - Why can't I access the value of the field in jsp (it returns null)? 为什么我不能使用realpath访问JSP文件中的图像? - Why can't I access the image in JSP file using realpath? 我们如何将json对象从servlet传输到jsp页面,以及如何在jsp页面中获取json数据? - How can we transfer json object from servlet to a jsp page and how to fetch that json data in jsp page? 为什么我们不能从内部的类构造函数访问另一个内部类? - Why can't we get access from the inner's class constructor to another inner class?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM