Content-type Camouflage-disguise JSP as CSS

Source: Internet
Author: User

First, pre-theoretical preparation

1) Purpose:
Dynamically generate CSS statements in the JSP and output them to the browser for parsing and rendering.
2) The browser parses the file according to:
After the page loads, the browser initiates individual requests to download various resources.
such as downloading CSS files, and then according to the CSS parsing rules to parse the document. If the downloaded file Content-type does not match, the browser will automatically block out.

Second, let JSP change the premise of CSS

Knowing the browser's parsing rules, JSP needs to do is to disguise their content-type as "text/css".

Third, directly on the code:

Index.html

<! DOCTYPE html>

css.jsp

<%@ page language= "java" contenttype= "text/html; Charset=utf-8 "pageencoding=" UTF-8 "session=" false "%><%    //Camouflage Response HTTP header    Response.setheader (" Content-type "," text/css ");        Output CSS style    out.clear ();    Out.print ("@charset \" utf-8\ "; \ n");    Out.print ("p{color:red;} \ n ");%>

Iv. Results



Successfully disguised JSP as a CSS file, browser parsing style success!

V. Expansion

According to this camouflage rule, the JSP can be disguised as arbitrary file format, as long as the browser can parse.
For example, disguised as JS, the Content-type is set to "Application/x-javascript"

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.