Struts2 Access action and JSP page path problem solution----for JSP, pictures, JS, CSS, etc. to get the absolute path of Web engineering __ajax

Source: Internet
Author: User
Way1: Embed Java code inside

The JSP page embeds the following code:

<%
String Path = Request.getcontextpath ();
String basepath = request.getscheme () + "://" +request.getservername () + ":" +request.getserverport () +path+ "/";
%>
Test Cases:
<script type= "Text/javascript" src= "<%=basepath%>/js/header.js" ></script>

Way2: via El expression

An explanation of the syntax for El expressions see: http://blog.csdn.net/qwerasdf123/article/details/4189889

Add the following code to the JSP page

<%@ taglib prefix= "C" uri= "Http://java.sun.com/jstl/core_rt"%> <c:set var=
"SC" >${ Pagecontext.request.contextpath}</c:set>

Test Cases:

<script type= "Text/javascript" src= "${sc}/js/header.js" ></script>

Note: The EL expression can only be used in the JSP page, no more JS and CSS and other format files to use. hard to find a two-hour error, only to find this problem. Hope you can learn the lesson, but also hope to help readers solve problems, save your precious time.

Related Article

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.