//basic code non strack algorithm just started learning java ignore space and time.
/// {[()]}[][]{}
// {[( -a -> }]) -b -> replace a(]}) -> reverse a( }]))->
//Split string to substring {[()]}, next [], next [], next{}
public class testbrackets {
static String stringfirst;
static String stringsecond;
static int open = 0;
public static void main(String[] args) {
splitstring("(()){}()");
}
static void splitstring(String str){
int len = str.length();
for(int i=0;i<=len-1;i++){
stringfirst="";
stringsecond="";
System.out.println("loop starttttttt");
char a = str.charAt(i);
if(a=='{'||a=='['||a=='(')
{
open = open+1;
continue;
}
if(a=='}'||a==']'||a==')'){
if(open==0){
System.out.println(open+"started with closing brace");
return;
}
String stringfirst=str.substring(i-open, i);
System.out.println("stringfirst"+stringfirst);
String stringsecond=str.substring(i, i+open);
System.out.println("stringsecond"+stringsecond);
replace(stringfirst, stringsecond);
}
i=(i+open)-1;
open=0;
System.out.println(i);
}
}
static void replace(String stringfirst, String stringsecond){
stringfirst = stringfirst.replace('{', '}');
stringfirst = stringfirst.replace('(', ')');
stringfirst = stringfirst.replace('[', ']');
StringBuilder stringfirst1 = new StringBuilder(stringfirst);
stringfirst = stringfirst1.reverse().toString();
System.out.println("stringfirst"+stringfirst);
System.out.println("stringsecond"+stringsecond);
if(stringfirst.equals(stringsecond)){
System.out.println("pass");
}
else{
System.out.println("fail");
System.exit(0);
}
}
}
Если при создании файла cookie указать путь к '/' вместо 'foo', вы сможете читать его в любом месте домена, включая '/ foo', '/ bar 'и др.
Вы не можете получить доступ к файлам cookie по другому пути - в противном случае это будет дыра в безопасности.
Единственный способ, который я могу придумать, - это установить / bar
файл cookie, путь которого = /
, чтобы все страницы в /
(включая / foo
) могли получить к нему доступ.
Как JJ и grawity упомянули, вы не можете сделать это со своей страницы. Однако у вас есть обходной путь.
i. Разместите iframe, указывающий на http: // localhost / bar . Имейте скрытый элемент на странице «панели», где вы храните значение cookie. (пусть этот iframe будет размером 1 * 1, чтобы его не было видно)
ii. Используйте JavaScript на странице "foo" для получения значения cookie.
Аналогичный подход (с изменениями) можно использовать и для записи значения cookie!
Спасибо,
Рамджи.