Requirements: HTML generated through the editor is uploaded to the Aliyun server, but the HTML needs to be embedded in another Web page. Environment Front-End: React backend: Java Java code
@RequestMapping (value = "/gethtml", method = Requestmethod.post)
@UnNeedAdminId
@Unauthorize
Public Object gethtml (@RequestBody map<string, string> uri) throws Exception {
url url = new URL (uri.get ("URL"));
URLConnection urlconnection = Url.openconnection ();
HttpURLConnection httpconnection = (httpurlconnection) urlconnection;
int responsecode = Httpconnection.getresponsecode ();
String str = "";
if (Responsecode = = HTTPURLCONNECTION.HTTP_OK) {
InputStream in = Httpconnection.getinputstream ();
InputStreamReader ISR = new InputStreamReader (in);
BufferedReader bufr = new BufferedReader (ISR);
String Lstr;
while ((Lstr = Bufr.readline ())!= null) {
str = str + lstr;
}
Bufr.close ();
} else {
str = "no content";
}
return str;
}
React Code
Export default class Phomelog extends React.component {static defaultprops = {};
Constructor (props) {super (props);
This.state = {sitecontent: ""}} Componentwillmount () {Let id = this.props.id;
Let URL = ' http://xxxxxxx/${id}/xxx.html ';
Fetch ({host: "XXX", url: ' api/gethtml ', body: {URL}, method: "POST",}). Then (RES) =>{ This.setstate ({siteContent:res.data})})} Createmarkup = (html) => {return {__HTML:HT
ML};
};
Replaces the characters that are escaped in the returned HTML escapechars= (str) => {str = str.replace (/&/g, ' & ');
str = str.replace (/</g, ' < ');
str = str.replace (/>/g, ' > ');
str = str.replace (/´/g, ' \ ');
str = str.replace (/"/g, ' "");
str = str.replace (/¦/g, ' \\| ');
str = str.replace (/& #x27;/g, ' \ ');
return str;
} render () {let {sitecontent} = this.state; Sitecontent = This.escapecHARs (sitecontent) return (<div> {sitecontent?) <div dangerouslysetinnerhtml={this.createmarkup (sitecontent)}></div>: <div className= "Pusht"
; ......</div>} </div>); }
}