Replace start and end text with empty - java

I have html like bellow
<html lang="en">
<head>
<meta http-equiv ...............
...................
</head> ..............
...............
</html>
I want to replace <head>.....</head> with ""(empty) and final string should look like this
<html lang="en">..............
....................
</html>
I tried with this but no luck nothing changed. any help is appreciated
myStr= myStr.replaceAll("^<head>.*</head>$", "");
System.out.println(myStr);

<head>\\s*([\\s\\S]*?)\\s*<\\/head>
You will have to replace by $1 here.See demo.
https://regex101.com/r/uF4oY4/20

Try This
String replStr = "<head>\\s*([\\s\\S]*?)\\s*</head>";
String yourHtml = "<html> <head> <meta http-equiv ............</head></html>";
yourHtml = yourHtml.replaceAll(replStr, "");
System.out.println("Ans : "+yourHtml);

Related

Enumeration<> Enumeration difference

I'm a biginner in JSP and I'm confused about the difference between
Enumeration and Enumeration<type>
I'm learning with this Korean book and the example source in it says Enumeration
with the eclipse neon version it doesn't work. It works only when it write
Enumeration<String>. Can someone tell me the difference?
<%#page import="java.util.Enumeration"%>
<%# page language="java" contentType="text/html;
charset=UTF-8"pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>헤더 목록 출력</title>
</head>
<body>
<%
Enumeration<String> headerEnum = request.getHeaderNames();
while(headerEnum.hasMoreElements()){
String headerName = (String)headerEnum.nextElement();
String headerValue = request.getHeader(headerName);
%>
<%=headerName %> = <%=headerValue %> <br>
<%
}
%>
</body>
</html>
Just give it a look at the Enumeration documentation. Also review the generic types documentation.
By usingEnumeration you are using Enumeration<Object> as it is the default. What this <Object> does is just indicate the Enumeration class that in that particular instance, the type that it calls E (in the Enumeration Documentation) will be resolved to Object. By using <String> happens the same: the type called E will be resolved to String.
If you check the nextElement() signature it returns E. So, by using Enumeration or Enumeration<Object> that method will return Object and you will need the cast you did:
String headerName = (String)headerEnum.nextElement();
By using Enumeration<String> the method will return an String, so you can directly do this:
String headerName = headerEnum.nextElement();

Split on pipe doesn't behave as expected

I have a code that get a HTML content from a page, then get the index of a specific strings, after that it splits it.
My problem is, It's not splitting right, Plus it's getting unwanted Strings .
Code :
URL = "https://drive.google.com/file/d/0B7--EhvK76QDRktKZm04MXVjVTQ/view";
html = Jsoup.connect(URL).get().html();
FirstDecoded = URLDecoder.decode(html, "UTF-8");
int Start = FirstDecoded.indexOf("[\"fmt_stream_map\"");
int End = FirstDecoded.indexOf("\"fmt_list\"");
String FirstSplit = FirstDecoded.substring(Start + 22, -5 + End);
String[] DummyTexts = {"<html>","<head>","</head>","<body>","</body>","</html"};
if(FirstSplit.contains(DummyTexts[0]))
FirstSplit.replace(DummyTexts[0],"");
if(FirstSplit.contains(DummyTexts[1]))
FirstSplit.replace(DummyTexts[1],"");
if(FirstSplit.contains(DummyTexts[2]))
FirstSplit.replace(DummyTexts[2],"");
if(FirstSplit.contains(DummyTexts[3]))
FirstSplit.replace(DummyTexts[3],"");
if(FirstSplit.contains(DummyTexts[4]))
FirstSplit.replace(DummyTexts[4],"");
FirstSplit.trim();
String[] Splitted = FirstSplit.split("|");
What i want :
Before Split
Url|Url|Url|Url
After Split
[0] = URL
[1] = 2nd URL
Result (What i don't want ) :
<!html>*a new line*<head></head>*a new line*<body>*a new line**white space*URL|URL|URL*a new line**2 White Space*</body></html>
If i try to split it, [0] is null, [1] is <! .
The HTML is :
<!doctype html>
<html>
<head>
<meta name="google" content="notranslate">
<meta http-equiv="X-UA-Compatible" content="IE=edge;">
<meta name="fragment" content="!">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=0">
<title>OnClick.mp4 - Google Drive</title>
<meta property="og:title" content="OnClick.mp4">
<meta property="og:type" content="article">
<meta property="og:site_name" content="Google Docs">
<script>(function(){(function(){function e(a){this.t={};this.tick=function(a,c,b){var d=void 0!=b?b:(new Date).getTime();this.t[a]=[d,c];if(void 0==b)try{window.console.timeStamp("CSI/" a)}catch(e){}};this.tick("start",null,a)}var a;window.performance&&(a=window.performance.timing);var f=a?new e(a.responseStart):new e;window.jstiming={Timer:e,load:f};if(a){var c=a.navigationStart,d=a.responseStart;0<c&&d>=c&&(window.jstiming.srt=d-c)}if(a){var b=window.jstiming.load;0<c&&d>=c&&(b.tick("_wtsrt",void 0,c),b.tick("wtsrt_",
"_wtsrt",d),b.tick("tbsd_","wtsrt_"))}try{a=null,window.chrome&&window.chrome.csi&&(a=Math.floor(window.chrome.csi().pageT),b&&0<c&&(b.tick("_tbnd",void 0,window.chrome.csi().startE),b.tick("tbnd_","_tbnd",c))),null==a&&window.gtbExternal&&(a=window.gtbExternal.pageT()),null==a&&window.external&&(a=window.external.pageT,b&&0<c&&(b.tick("_tbnd",void 0,window.external.startE),b.tick("tbnd_","_tbnd",c))),a&&(window.jstiming.pt=a)}catch(g){}})();})();
</script>
<script>window.gapi_onload=function(){};var scriptEl$$inline_0=document.createElement("script");scriptEl$$inline_0.src="https://apis.google.com/js/client.js";scriptEl$$inline_0.async=!0;var firstScriptEl$$inline_1=document.getElementsByTagName("script")[0];firstScriptEl$$inline_1.parentNode.insertBefore(scriptEl$$inline_0,firstScriptEl$$inline_1);
</script>
<link rel="shortcut icon" href="https://ssl.gstatic.com/docs/doclist/images/icon_14_video_favicon.ico">
<link rel="stylesheet" href="/static/file/client/css/2745349237-projector_css_rtl.css">
<script>_docs_flag_initialData={"docs-aiiws":"docs_cold_nf","docs-ails":"docs_cold","docs-fwds":"docs_nf","info_params":{},"docosEmbedApiJs":"//docs.google.com/comments/d/AAHRpnXuhyO5yfTCPldRcxO-Xq_Srdd0JamOO8LslEPvYPeUzPnTtftedmIsqUWcNeSJHWF2hg2WdKe4Zpf5PRuBTzieIUoGG1g/api/js?hl\u003dar","docosUnreadCommentsEnabled":false,"uls":"","icso":false,"docs_oogt":"NONE","docs-egc":true,"docs-chat_wabel":false,"docs-ce":true,"docs-ut":2,"docs-chat_base_url":"talkgadget.google.com/talkgadget/","docs-chat_domain_rotation":true,"docs-cwd":"","docs-epuv2":false,"promo_url":"","promo_title":"","promo_title_prefix":"","promo_content_html":"","promo_link_text":"","promo_element_id":"","promo_orientation":1,"promo_show_on_click":false,"promo_show_on_load":false,"show_promo":false,"promo_mark_dismissed_on_show":false,"promo_use_global_preference":false,"promo_close_button_text":"","docs-encp":false,"buildLabel":"texmex_2016.05-Thu_RC0","docs-show_debug_info":false,"ondlburl":"//docs.google.com","drive_url":"//drive.google.com","app_url":"https://drive.google.com/file/","docs-mid":2048,"docs-eicd":false,"docs-icdmt":[],"docs-sup":"/file","docs-uptc":["lsrp","noreplica","usp","urp","utm_source","utm_medium","utm_campaign","utm_term","utm_content","sle"],"docs-cwsd":"","docs-al":[0,0,0,1,0],"docs-ndt":"Untitled Texmex","docs-rpe":false,"docs-mdck":"","docs-mas":"","docs-etiff":false,"docs-spfe":true,"docs-mriim":1800000,"docs-eccbs":false,"docs-net-ernjp":false,"docos-sosj":false,"docs-rlmp":false,"docs-mmpt":15000,"docs-erd":false,"docs-erfar":false,"docs-ssi":false,"docs-ema":false,"docs-escd":false,"docs-ensb":false,"docs-epwf":false,"ecid":true,"docs-emo":false,"docs-eos":false,"docs-pedd":true,"docs-eir":false,"docs-dc":false,"docs-edll":false,"docs-eivu":false,"server_time_ms":1455582166639,"gaia_session_id":"","app-bc":"#d1d1d1","enable_iframed_embed_api":true,"docs-fut":"//drive.google.com#folders/{folderId}","esid":true,"esubid":false,"docs-etbs":true,"docs-isb":false,"docs-pid":"","docs-mib":5242880,"docs-mip":6250000,"enable_kennedy":true,"docs-gth":"","opendv":false,"onePickImportDocumentUrl":"","opmbs":5242880,"opmpd":2500,"opbu":"https://docs.google.com/picker","opru":"https://drive.google.com/relay.html","opdu":false,"opccp":false,"ophi":"texmex","opst":"000770F2037BC252B6F708ED31726B33CE13CDBE7A86BF0E7B","opuci":"","jobset":"prod","docs-se":false,"docs-ebcrsct":false,"docs-iror":true,"enable_client_docos":true,"enable_anchored_docos":true,"enable_docos_tickle":true,"enable_pinned_revisions":false,"enable_edit_blob_revisions":false,"upload_url":"https://docs.google.com/upload/resumableupload","enable_toolbar":true,"enable_link_opener":true,"enable_microscope":true,"enable_manage_timed_text":true,"video_embed_type":"PREFER_FLASH","enable_maps_embed":false,"maps_api_uri":"https://maps.googleapis.com/maps/api/js?key\u003dAIzaSyBCjpnguVjzi6vS67NdBtyYuvCYz3yBxCY&sensor\u003dfalse","maps_display_uri":"https://maps.google.com/maps","docs-epcc":false,"docs_abuse_link":"https://docs.google.com/abuse?id\u003d0B7--EhvK76QDRktKZm04MXVjVTQ","enable_csi":true,"csi_service_name":"texmex","third_party_default_icon_urls":{"icon16":"//ssl.gstatic.com/docs/doclist/images/generic_app_icon_16.png","icon32":"//ssl.gstatic.com/docs/doclist/images/generic_app_icon_32.png","icon64":"//ssl.gstatic.com/docs/doclist/images/generic_app_icon_64.png","icon128":"//ssl.gstatic.com/docs/doclist/images/generic_app_icon_128.png"},"enable_chrome_webstore_link":true};</script>
</head>
<body dir="rtl" role="application" onload="_onProjectorLoad();" onunload="_disposeProjector();">
<meta itemprop="name" content="OnClick.mp4">
<meta itemprop="faviconUrl" content="https://ssl.gstatic.com/docs/doclist/images/icon_14_video_favicon.ico">
<script type="text/javascript" src="/static/file/client/js/2068619951-projector_viewer__ar.js"></script>
<script>_initProjector({'id': '0B7--EhvK76QDRktKZm04MXVjVTQ', 'title': 'OnClick.mp4','isMobileWeb': true,'enableStandaloneSharing': true,'enableEmbedDialog': true,'projectorFeedbackId': '99950', 'projectorFeedbackBucket': 'viewer-web',},["",0,,1,1,1,1,,,1,0,[0,,0,"AIzaSyDVQw45DwoYh632gvsP5vPDqEKvb-Ywnb8",0,0,1,0,,,0,"/drive/v2internal",0,0,0,[0,0,0]
,0,1]
,1,5,1,,0,1,"https://docs.google.com",0,1,1,1,1,,1,20,1,0,0,1,1,[[,"0"]
,6,1,1,"ND"]
,0,0,1,,[0,,,,"https://accounts.google.com/ServiceLogin?service\u003dwise&passive\u003d1209600&continue\u003dhttps://drive.google.com/file/d/0B7--EhvK76QDRktKZm04MXVjVTQ/view&hl\u003dar&followup\u003dhttps://drive.google.com/file/d/0B7--EhvK76QDRktKZm04MXVjVTQ/view"]
,0,1,1,600000,,"https://docs.google.com",0,0,[0,1,1,1]
,["https://youtube.googleapis.com",1,2]
,1,1,,0,1,1,1,0,,,,,[1,1,1,1]
,,1,0,2,0,0,[0,"https://maps.googleapis.com/maps/api/js?key\u003dAIzaSyBCjpnguVjzi6vS67NdBtyYuvCYz3yBxCY&sensor\u003dfalse"]
,0]
,[,"OnClick.mp4","https://lh4.googleusercontent.com/pI9y-A5tCOzi0W7eYAMzgqPHfzuBbq2wno4s2mvkrgc-JNtHtHWU36w0iICXMsRjxaAFuJ0p\u003dw1600-rw",,,,"0B7--EhvK76QDRktKZm04MXVjVTQ",,,,,"video/mp4",,,0,,"https://drive.google.com/file/d/0B7--EhvK76QDRktKZm04MXVjVTQ/view",1,"https://docs.google.com/uc?id\u003d0B7--EhvK76QDRktKZm04MXVjVTQ&export\u003ddownload",[[["status","ok"]
,["hl","ar"]
,["allow_embed","0"]
,["ps","docs"]
,["partnerid","30"]
,["autoplay","0"]
,["docid","0B7--EhvK76QDRktKZm04MXVjVTQ"]
,["abd","0"]
,["public","true"]
,["el","leaf"]
,["title","OnClick.mp4"]
,["BASE_URL","https://drive.google.com/"]
,["iurl","https://docs.google.com/vt?id\u003d0B7--EhvK76QDRktKZm04MXVjVTQ"]
,["ttsurl","https://drive.google.com/timedtext?id\u003d0B7--EhvK76QDRktKZm04MXVjVTQ&vid\u003d1089c9d5a380c541"]
,["reportabuseurl","https://drive.google.com/abuse?id\u003d0B7--EhvK76QDRktKZm04MXVjVTQ"]
,["token","1"]
,["plid","V0QUM0REiMM2sQ"]
,["fmt_stream_map","37|https://r13---sn-hpa7ln7k.c.docs.google.com/videoplayback?requiressl\u003dyes&id\u003d1089c9d5a380c541&itag\u003d37&source\u003dwebdrive&app\u003dtexmex&ip\u003d5.0.148.212&ipbits\u003d8&expire\u003d1455596566&sparams\u003drequiressl,id,itag,source,ip,ipbits,expire&signature\u003d3DC24BBB45AB0C09B1633ABC215282DAD3275086.1E524A3C98B38084443AF227B4676FA122CB7191&key\u003dck2&mm\u003d30&mn\u003dsn-hpa7ln7k&ms\u003dnxu&mt\u003d1455582034&mv\u003dm&pl\u003d18,22|https://r13---sn-hpa7ln7k.c.docs.google.com/videoplayback?requiressl\u003dyes&id\u003d1089c9d5a380c541&itag\u003d22&source\u003dwebdrive&app\u003dtexmex&ip\u003d5.0.148.212&ipbits\u003d8&expire\u003d1455596566&sparams\u003drequiressl,id,itag,source,ip,ipbits,expire&signature\u003d92CE58A6991267C1E6F28C23DC9C03F5CF7E0C7A.77E9DBA8D81F681587D68E2C9EF942DAA37D8461&key\u003dck2&mm\u003d30&mn\u003dsn-hpa7ln7k&ms\u003dnxu&mt\u003d1455582034&mv\u003dm&pl\u003d18,35|https://r13---sn-hpa7ln7k.c.docs.google.com/videoplayback?requiressl\u003dyes&id\u003d1089c9d5a380c541&itag\u003d35&source\u003dwebdrive&app\u003dtexmex&ip\u003d5.0.148.212&ipbits\u003d8&expire\u003d1455596566&sparams\u003drequiressl,id,itag,source,ip,ipbits,expire&signature\u003d92E5A471515BC4145F258D67C6E52F7CA0FA2530.73516C4866808CD98769225F3623A93613B65F1E&key\u003dck2&mm\u003d30&mn\u003dsn-hpa7ln7k&ms\u003dnxu&mt\u003d1455582034&mv\u003dm&pl\u003d18,59|https://r13---sn-hpa7ln7k.c.docs.google.com/videoplayback?requiressl\u003dyes&id\u003d1089c9d5a380c541&itag\u003d59&source\u003dwebdrive&app\u003dtexmex&ip\u003d5.0.148.212&ipbits\u003d8&expire\u003d1455596566&sparams\u003drequiressl,id,itag,source,ip,ipbits,expire&signature\u003d66DCB19D441D9742A4D21F1A08CDF488C81F728D.1864D7646337ED87C9A82951A0D524B6B3CEF451&key\u003dck2&mm\u003d30&mn\u003dsn-hpa7ln7k&ms\u003dnxu&mt\u003d1455582034&mv\u003dm&pl\u003d18,34|https://r13---sn-hpa7ln7k.c.docs.google.com/videoplayback?requiressl\u003dyes&id\u003d1089c9d5a380c541&itag\u003d34&source\u003dwebdrive&app\u003dtexmex&ip\u003d5.0.148.212&ipbits\u003d8&expire\u003d1455596566&sparams\u003drequiressl,id,itag,source,ip,ipbits,expire&signature\u003d1837C0B9C77AF259371C0239C7B56C68C43B86A0.68E22AF960C1C023033FD24D1138AFBE91CD02D3&key\u003dck2&mm\u003d30&mn\u003dsn-hpa7ln7k&ms\u003dnxu&mt\u003d1455582034&mv\u003dm&pl\u003d18,18|https://r13---sn-hpa7ln7k.c.docs.google.com/videoplayback?requiressl\u003dyes&id\u003d1089c9d5a380c541&itag\u003d18&source\u003dwebdrive&app\u003dtexmex&ip\u003d5.0.148.212&ipbits\u003d8&expire\u003d1455596566&sparams\u003drequiressl,id,itag,source,ip,ipbits,expire&signature\u003d9208D71BE0BCBE4B3DF1E7B922159C3BE921FA05.2A991F268E18F480929B6A98B107468601A55535&key\u003dck2&mm\u003d30&mn\u003dsn-hpa7ln7k&ms\u003dnxu&mt\u003d1455582034&mv\u003dm&pl\u003d18,43|https://r13---sn-hpa7ln7k.c.docs.google.com/videoplayback?requiressl\u003dyes&id\u003d1089c9d5a380c541&itag\u003d43&source\u003dwebdrive&app\u003dtexmex&ip\u003d5.0.148.212&ipbits\u003d8&expire\u003d1455596566&sparams\u003drequiressl,id,itag,source,ip,ipbits,expire&signature\u003d5720BE679324A8AE30BA464F81AE61CB6A551C1.69D6E187577E285BF9C2BF0415AD929EFA212D45&key\u003dck2&mm\u003d30&mn\u003dsn-hpa7ln7k&ms\u003dnxu&mt\u003d1455582034&mv\u003dm&pl\u003d18"]
,["fmt_list","37/1920x1080/9/0/115,22/1280x720/9/0/115,35/854x480/9/0/115,59/854x480/9/0/115,34/640x360/9/0/115,18/640x360/9/0/115,43/640x360/99/0/0"]
,["url_encoded_fmt_stream_map","itag\u003d37&url\u003dhttps://r13---sn-hpa7ln7k.c.docs.google.com/videoplayback?requiressl=yes&id=1089c9d5a380c541&itag=37&source=webdrive&app=texmex&ip=5.0.148.212&ipbits=8&expire=1455596566&sparams=requiressl,id,itag,source,ip,ipbits,expire&signature=3DC24BBB45AB0C09B1633ABC215282DAD3275086.1E524A3C98B38084443AF227B4676FA122CB7191&key=ck2&mm=30&mn=sn-hpa7ln7k&ms=nxu&mt=1455582034&mv=m&pl=18&type\u003dvideo/mp4; codecs="avc1.42001E, mp4a.40.2"&quality\u003dhd1080,itag\u003d22&url\u003dhttps://r13---sn-hpa7ln7k.c.docs.google.com/videoplayback?requiressl=yes&id=1089c9d5a380c541&itag=22&source=webdrive&app=texmex&ip=5.0.148.212&ipbits=8&expire=1455596566&sparams=requiressl,id,itag,source,ip,ipbits,expire&signature=92CE58A6991267C1E6F28C23DC9C03F5CF7E0C7A.77E9DBA8D81F681587D68E2C9EF942DAA37D8461&key=ck2&mm=30&mn=sn-hpa7ln7k&ms=nxu&mt=1455582034&mv=m&pl=18&type\u003dvideo/mp4; codecs="avc1.42001E, mp4a.40.2"&quality\u003dhd720,itag\u003d35&url\u003dhttps://r13---sn-hpa7ln7k.c.docs.google.com/videoplayback?requiressl=yes&id=1089c9d5a380c541&itag=35&source=webdrive&app=texmex&ip=5.0.148.212&ipbits=8&expire=1455596566&sparams=requiressl,id,itag,source,ip,ipbits,expire&signature=92E5A471515BC4145F258D67C6E52F7CA0FA2530.73516C4866808CD98769225F3623A93613B65F1E&key=ck2&mm=30&mn=sn-hpa7ln7k&ms=nxu&mt=1455582034&mv=m&pl=18&type\u003dvideo/x-flv&quality\u003dlarge,itag\u003d59&url\u003dhttps://r13---sn-hpa7ln7k.c.docs.google.com/videoplayback?requiressl=yes&id=1089c9d5a380c541&itag=59&source=webdrive&app=texmex&ip=5.0.148.212&ipbits=8&expire=1455596566&sparams=requiressl,id,itag,source,ip,ipbits,expire&signature=66DCB19D441D9742A4D21F1A08CDF488C81F728D.1864D7646337ED87C9A82951A0D524B6B3CEF451&key=ck2&mm=30&mn=sn-hpa7ln7k&ms=nxu&mt=1455582034&mv=m&pl=18&type\u003dvideo/mp4; codecs="avc1.42001E, mp4a.40.2"&quality\u003dlarge,itag\u003d34&url\u003dhttps://r13---sn-hpa7ln7k.c.docs.google.com/videoplayback?requiressl=yes&id=1089c9d5a380c541&itag=34&source=webdrive&app=texmex&ip=5.0.148.212&ipbits=8&expire=1455596566&sparams=requiressl,id,itag,source,ip,ipbits,expire&signature=1837C0B9C77AF259371C0239C7B56C68C43B86A0.68E22AF960C1C023033FD24D1138AFBE91CD02D3&key=ck2&mm=30&mn=sn-hpa7ln7k&ms=nxu&mt=1455582034&mv=m&pl=18&type\u003dvideo/x-flv&quality\u003dmedium,itag\u003d18&url\u003dhttps://r13---sn-hpa7ln7k.c.docs.google.com/videoplayback?requiressl=yes&id=1089c9d5a380c541&itag=18&source=webdrive&app=texmex&ip=5.0.148.212&ipbits=8&expire=1455596566&sparams=requiressl,id,itag,source,ip,ipbits,expire&signature=9208D71BE0BCBE4B3DF1E7B922159C3BE921FA05.2A991F268E18F480929B6A98B107468601A55535&key=ck2&mm=30&mn=sn-hpa7ln7k&ms=nxu&mt=1455582034&mv=m&pl=18&type\u003dvideo/mp4; codecs="avc1.42001E, mp4a.40.2"&quality\u003dmedium,itag\u003d43&url\u003dhttps://r13---sn-hpa7ln7k.c.docs.google.com/videoplayback?requiressl=yes&id=1089c9d5a380c541&itag=43&source=webdrive&app=texmex&ip=5.0.148.212&ipbits=8&expire=1455596566&sparams=requiressl,id,itag,source,ip,ipbits,expire&signature=5720BE679324A8AE30BA464F81AE61CB6A551C1.69D6E187577E285BF9C2BF0415AD929EFA212D45&key=ck2&mm=30&mn=sn-hpa7ln7k&ms=nxu&mt=1455582034&mv=m&pl=18&type\u003dvideo/webm&quality\u003dmedium"]
,["timestamp","1455582166637"]
,["length_seconds","19"]
]
]
,5,0,,,,,,,,,,1,"mp4"]
);</script>
</body>
</html>
Not spending too much time looking at your logic, I can see that you think
FirstSplit.replace(DummyTexts[0],"");
actually changes the String FirstSplit, which it doesn't. In Java Strings are immutable, so they can't change.
Replace all those lines with something like this (obviously with different indexes in DummyTexts):
FirstSplit = FirstSplit.replace(DummyTexts[0], "");
Note that this doesn't change FirstSplit, it just changes what String FirstSplit refers to, setting it to the new String being returned by the replace method. That might get you what you want, assuming the rest of that stuff works.
Ok, you say you changed to this and it still didn't work. That's probably because the FirstDecoded string you're creating is basically the fmt_stream_map line from the HTML you listed (minus a few characters at the front and back):
"fmt_stream_map","37|https://r13---sn-hpa7ln7k.c.docs.google.com/videoplayback?requiressl\u003dyes&id\u003d1089c9d5a380c541&itag\u003d37&source\u003dwebdrive&app\u003dtexmex&ip\u003d5.0.148.212&ipbits\u003d8&expire\u003d1455596566&sparams\u003drequiressl,id,itag,source,ip,ipbits,expire&signature\u003d3DC24BBB45AB0C09B1633ABC215282DAD3275086.1E524A3C98B38084443AF227B4676FA122CB7191&key\u003dck2&mm\u003d30&mn\u003dsn-hpa7ln7k&ms\u003dnxu&mt\u003d1455582034&mv\u003dm&pl\u003d18,22|https://r13---sn-hpa7ln7k.c.docs.google.com/videoplayback?requiressl\u003dyes&id\u003d1089c9d5a380c541&itag\u003d22&source\u003dwebdrive&app\u003dtexmex&ip\u003d5.0.148.212&ipbits\u003d8&expire\u003d1455596566&sparams\u003drequiressl,id,itag,source,ip,ipbits,expire&signature\u003d92CE58A6991267C1E6F28C23DC9C03F5CF7E0C7A.77E9DBA8D81F681587D68E2C9EF942DAA37D8461&key\u003dck2&mm\u003d30&mn\u003dsn-hpa7ln7k&ms\u003dnxu&mt\u003d1455582034&mv\u003dm&pl\u003d18,35|https://r13---sn-hpa7ln7k.c.docs.google.com/videoplayback?requiressl\u003dyes&id\u003d1089c9d5a380c541&itag\u003d35&source\u003dwebdrive&app\u003dtexmex&ip\u003d5.0.148.212&ipbits\u003d8&expire\u003d1455596566&sparams\u003drequiressl,id,itag,source,ip,ipbits,expire&signature\u003d92E5A471515BC4145F258D67C6E52F7CA0FA2530.73516C4866808CD98769225F3623A93613B65F1E&key\u003dck2&mm\u003d30&mn\u003dsn-hpa7ln7k&ms\u003dnxu&mt\u003d1455582034&mv\u003dm&pl\u003d18,59|https://r13---sn-hpa7ln7k.c.docs.google.com/videoplayback?requiressl\u003dyes&id\u003d1089c9d5a380c541&itag\u003d59&source\u003dwebdrive&app\u003dtexmex&ip\u003d5.0.148.212&ipbits\u003d8&expire\u003d1455596566&sparams\u003drequiressl,id,itag,source,ip,ipbits,expire&signature\u003d66DCB19D441D9742A4D21F1A08CDF488C81F728D.1864D7646337ED87C9A82951A0D524B6B3CEF451&key\u003dck2&mm\u003d30&mn\u003dsn-hpa7ln7k&ms\u003dnxu&mt\u003d1455582034&mv\u003dm&pl\u003d18,34|https://r13---sn-hpa7ln7k.c.docs.google.com/videoplayback?requiressl\u003dyes&id\u003d1089c9d5a380c541&itag\u003d34&source\u003dwebdrive&app\u003dtexmex&ip\u003d5.0.148.212&ipbits\u003d8&expire\u003d1455596566&sparams\u003drequiressl,id,itag,source,ip,ipbits,expire&signature\u003d1837C0B9C77AF259371C0239C7B56C68C43B86A0.68E22AF960C1C023033FD24D1138AFBE91CD02D3&key\u003dck2&mm\u003d30&mn\u003dsn-hpa7ln7k&ms\u003dnxu&mt\u003d1455582034&mv\u003dm&pl\u003d18,18|https://r13---sn-hpa7ln7k.c.docs.google.com/videoplayback?requiressl\u003dyes&id\u003d1089c9d5a380c541&itag\u003d18&source\u003dwebdrive&app\u003dtexmex&ip\u003d5.0.148.212&ipbits\u003d8&expire\u003d1455596566&sparams\u003drequiressl,id,itag,source,ip,ipbits,expire&signature\u003d9208D71BE0BCBE4B3DF1E7B922159C3BE921FA05.2A991F268E18F480929B6A98B107468601A55535&key\u003dck2&mm\u003d30&mn\u003dsn-hpa7ln7k&ms\u003dnxu&mt\u003d1455582034&mv\u003dm&pl\u003d18,43|https://r13---sn-hpa7ln7k.c.docs.google.com/videoplayback?requiressl\u003dyes&id\u003d1089c9d5a380c541&itag\u003d43&source\u003dwebdrive&app\u003dtexmex&ip\u003d5.0.148.212&ipbits\u003d8&expire\u003d1455596566&sparams\u003drequiressl,id,itag,source,ip,ipbits,expire&signature\u003d5720BE679324A8AE30BA464F81AE61CB6A551C1.69D6E187577E285BF9C2BF0415AD929EFA212D45&key\u003dck2&mm\u003d30&mn\u003dsn-hpa7ln7k&ms\u003dnxu&mt\u003d1455582034&mv\u003dm&pl\u003d18"] ,[
This doesn't have any of the strings you're looking for in it....
Ok, so now you're wondering why splitting the whole page gives you crazy results, and it's because split() takes a regex argument, not just a String. A single pipe '|' is not valid regex, use "\|" instead (escaped the special character).
https://docs.oracle.com/javase/7/docs/api/java/lang/String.html#split(java.lang.String)

Unable to decode utf-8 using thai language?

This is my JSP page:
<%--
Document : new jsp1
Created on : Nov 24, 2014, 12:38:07 PM
Author : Java
--%>
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<%
String msg="206_John_help i m in trouble,delhi,อินเดีย_30.64741430_76.817313799";
String result = java.net.URLEncoder.encode(msg, "UTF-8");
System.out.println("The msg is "+result);
String result1=java.net.URLDecoder.decode(result, "UTF-8");
System.out.println("The decoded msg is "+result1);
%>
</body>
</html>
The output is 206_John_help i m in trouble,delhi,???????_30.64741430_76.817313799
I am always getting ?????? instead of thai alphabets. How can I get the Thai alphabets while decoding?
The problem is not on encoding and decoding the messages but in the server container. Seems that server cant display properly the special characters, so it can not treat them from request.
If you display the values in the JSP page itself, everything is working fine.
Example:
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<%
String msg="206_John_help i m in trouble,delhi,อินเดีย_30.64741430_76.817313799";
System.out.println("The original message "+msg);
String result = java.net.URLEncoder.encode(msg, "UTF-8");
System.out.println("The msg is "+result);
String result1=java.net.URLDecoder.decode(result, "UTF-8");
System.out.println("The decoded msg is "+result1);
%>
Original message <%=msg %><br />
Encrypted message <%=result %> <br />
Decrypted message <%=result1 %>
</body>
</html>

jsp: how to get value from session?

I get an String array from session and I want to show the String from the array.
I know javascript can't get data from session directly. Is there any method I can get the data from session and transfer it to javascrip?
My code as follows:
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%String[] sele = (String[])session.getAttribute("selections");%>;
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta http-equiv="Expires" content="0">
<meta http-equiv="kiben" content="no-cache">
<title>Check List</title>
<script language="javascript" type="text/JavaScript" src="cookie.js">
</script>
<script text="text/javascript">
{
var selections = //String array form session
for(var v=0;v<selections.length;v++){
fillForm(selections[v]);
}
}
function fillForm(name){
var checkbox= document.createElement("input");
checkbox.type="checkbox";
checkbox.name=name;
checkbox.value=name;
checkbox.id=name;
var label = document.createElement("label");
label.htmlFor="id";
label.appendChild(document.createTextNode(name));
var container = document.getElementById("checklist");
container.appendChild(checkbox);
container.appendChild(label);
container.appendChild(document.createElement("br"));
}
function submitAction(){
addUserName(document.getElementById("checklist"));
var elem = document.getElementById("checklist").elements;
for(i =0;i<elem.length;i++){
elem[i].checked = true;
}
var form = document.getElementById("checklist");
form.submit();
}
</script>
</head>
<body>
<form id="checklist" action="selection">
</form>
<Button type="button" onclick="submitAction()" name="submit">Submit</button>
</body>
</html>
Simply use JSP Expression Language and JSP JSTL
<script>
alert("value: ${selections}");
</script>
Here selections is an attribute that is set in any scope page, request, session or application.
You can directly access an attribute form session scope:
{sessionScope.selections}
Note: I don't know that Java ArrayList does work in JavaScript as well. If it doesn't work then simply set a comma separated string as session attribute and split it in JavaScript as shown below.
Sample code:
<script>
var selections = "${sessionScope.csv}".split(",");
for ( var v = 0; v < selections.length; v++) {
alert(selections[v]);
}
</script>
Here csv is a comma separated string value that is set in session scope.
Use JSP JSTL and EL instead of Scriplet that is more easy to use and less error prone.
You can achieve it in JSTL without using JavaScript. Simply iterate the list using <c:forEach> tag and add that much of check boxes and labels.
Sample code:
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
...
<body>
...
<c:forEach items="${selections }" var="name">
<input type="checkbox" name="${name}" value="${name}" id="${name}">
...
</c:forEach>
</body>

How to use jsp variable in javascript array?

Hi I have a jsp page where I have some variable. I want to access the variable in a javascript array. How can I get this?
Demo.jsp
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<%
int i=1;
int j=2;
int k=3;
int l=4;
%>
</body>
</html>
I want to use these 4 variables in the javascript array and print them.
How can I achieve this?
Try,
<script language="JavaScript">
var Arr = new Array();
Arr[0] = '<%=i %>';
Arr[1] = '<%=j %>';
Arr[2] = '<%=k %>';
Arr[3] = '<%=l %>';
</script>
In Java script you have to use scriplet tag to use jsp data.
<%
Integet a = i ; //here i is your jsp variable
%>
In order to make this work you should declare the variable before using it (as always):
<%
String myVar="blabla";
%>
<script type="text/javascript">
foo();
function foo() {
var value = "<%=myVar%>";
alert(value);
}
</script>
Or :
var result = [];
result.push(<%i%>);
result.push(<%j%>);
result.push(<%k%>);
result.push(<%l%>);
You can access it using JSTL.
set java variable to JSTL variable
Access it in Java script as
var x='${jstl_varialbe_goes_here
}';
alert(x);

Categories