${pagecontext.request.contextpath} in Java

Source: Internet
Author: User

${pagecontext.request.contextpath} was previously contacted in the DRP project. No attention at the time. This time in the Java version of the University cloud Platform ITOO4.0 meet again, really wuqiaobuchengshu ah. Encountered again. If I don't leave it, I'll just say go.

Before we say this, we have to talk about the El expression in a nutshell.

  el expression

EL full name is Expressionlanguage. Functions are:

? Get Data: 

El expressions are primarily used to replace script expressions in JSP pages. To retrieve Java objects from various types of Web domains and get data. (An object in a web domain.) Visit the properties of the JavaBean, visit the list collection, visit the Map collection, and access the array of questions.

? Operation Operation: 

The EL expression allows you to run some of the main relational, logical, and arithmetic operations on the JSP page to complete some simple logic operations on the JSP page. ${user==null}

? Get web development frequently use objects 

An EL expression defines some implicit objects. With these implicit objects, web developers can easily get a reference to the web's frequently used objects to get the data in those objects.

? Calling the Java method 

The EL expression agrees with the user to develop their own definition El function to invoke the Java class method in the JSP page through an El expression.

  For data acquisition, it is mainly used in the following ways:

Get data syntax using el expression: "${ identifier }"

EL When an expression statement is run, it calls the Pagecontext.findattribute method. Use identifiers as keyword, from page,request,session, Application finds the corresponding object in four fields, returns the corresponding object if found, and returns "" if not found(note. is not null. Instead of an empty string).

  ${pagecontext.request.contextpath}

{PageContext.request.contextPath} is actually the notation of an El expression that takes the data from the Get method using the principle of the El Get value:

pagecontext.getrequest () get the HttpServletRequest object. This is the first step, and the second step is to call the Getcontextpath method with the httpservletrequest you get.

The role is to remove the deployed application name so that no matter how it is deployed, the path used is correct.

The pros and cons of other ways to get paths:

Http://www.cnblogs.com/langtianya/archive/2013/03/04/2942515.html

In addition, everyone used to use the JSP script output: in detail:

 <%=request.getcontextpath ()%> the function is to be able to return the name of the app where the current page is located.

? El better than script <%%>  

1, El expression with ${}, can be used in all the HTML and JSP tag role is to replace the JSP page complex Java code.

2. An El expression can manipulate constant variables and implicit objects. The most frequently used implicit objects are ${param} and ${paramvalues}. ${param} represents a value that returns a single string in the request parameter. ${paramvalues} Represents a set of values that returns the number of requests. Pagescope represents a variable for a page range. Requestscope represents a variable for the Request object. Sessionscope represents a variable in the session scope. Applicationscope represents the variable that is scoped to the application.

3. <% @pageisELIgnored = "true"%> indicates whether the El language is disabled, and true to suppress. False indicates that the. JSP2.0 enabled El language is not suppressed by default.

4. The El language can display a logical expression such as ${trueand false} The result is a false relationship expression such as ${5>6} result is false arithmetic expression such as ${5+5} result is 10

5. The variable search scope in El is: page,equest,session,application dot operator (.) and "[]" are the values that represent getting variables. The difference is [] the ability to display non-speech variables

 small expansion of knowledge

Request.getscheme () + "://" +request.getservername () + ":" +request.getserverport () +path+ "/"; This is also a very common expression in the DRP project, Used frequently before we use ${pagecontext.request.contextpath}.

So what exactly does that mean?

Seems difficult to understand. The fact is to get the app's root URL. Or an interview address, for example. We often visit the number 8080port of the local address. namely http://localhost:8080;

Detailed Explanation:

1, Request.getscheme () returns the name of the protocol HTTP, and the following "://" to spell it becomes HTTP//

2, Request.getservername () This is the name of your server this machine is localhost or 127.0.0.1, which means the local

3, Request.getserverport () return port number, for example 8080

Summary

I have a little memory of these three. summed up a bit. Suddenly more clear, knowledge or particles ah.


${pagecontext.request.contextpath} in Java

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.