just add url on only address bar of browser [duplicate] - java

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Change the URL in the browser without loading the new page using JavaScript
i want just add url in address bar of browser Note: dont want redirect
e.i i have a url www.example.com/index.html
i want set url on 'address bar' like www.example.com/index/page2.html
i use document.location.hash = 'foo';
but it is add only # data
like www.example.com/index.html#foo
note : i dont want to redirect only want to add url in address bar so don't answer document.location like that
any solution for that ?

Have a read here.
http://badassjs.com/post/840846392/location-hash-is-dead-long-live-html5-pushstate
Might help.
window.history.pushState('abc', "Title", "/new-url");

Can't be done. This is a security feature to make it harder to spoof a site (e.g. for phishing attacks)

I'm not sure if you can do this without using a redirect.
Here's a way to achieve your goal though.
Create page for www.example.com/index/page2.html that contains of a frame of www.example.com/index.html
In www.example.com/index.html redirect the user to www.example.com/index/page2.html if the www.example.com/index.html isn't inside a frame.

Related

What to post in HTTP POST

I am working on an android app which helps the user login. The site which I want to login is this
I have been now searching for 2 days straight but haven't found myself any answer as to what all I should post.
The problem that I am facing is what all parameters should I post ? I have tried every possible combination of hidden and non-hidden and also tried with cookies.
It would be really kind of you if you could give me the list of the parameters that I should include in my request.
As of now , this is my code
Document docl = Jsoup.connect("http://erp.mitpune.com/AdminLogin.aspx")
.data("__VIEWSTATE","/wEPDwUINDA4MDU2ODdkZGYVkCI+Zarbu9B42es/RUu7ZNbD")
.data("txtPassword","*******")
.data("__LASTFOCUS","")
.data("__EVENTTARGET","")
.data("__EVENTARGUMENT","")
.data("__VIEWSTATE","/wEPDwUINDA4MDU2ODdkZGYVkCI+Zarbu9B42es/RUu7ZNbD")
.data("__VIEWSTATEGENERATOR","B8B84CAE")
.data("hdnMsg","")
.data("txtUserId","********")
.data("btnLogin","Login")
.method(Connection.Method.POST).post();
I am using jsoup,on android studio, but just the list would help me a lot.
Thanks in advance
txtUserId and txtPassword
posted to Adminlogin.aspx
inside form1
so form1.txtUserId and form1.txtPassword
This is a quick output of data variables by Fiddler Chrome Extension
ScriptManager1: UpdatePanel1|btnLogin
__ASYNCPOST: true
__EVENTARGUMENT:
__EVENTTARGET: btnLogin
__LASTFOCUS:
__VIEWSTATE: /wEPDwUINDA4MDU2ODdkZGYVkCI+Zarbu9B42es/RUu7ZNbD
__VIEWSTATEGENERATOR: B8B84CAE
hdnMsg:
txtPassword: sasasa
txtUserId: jajas
Seems like _ASYNCPOST and ScriptManager1 are not in your post variables .

Make gwt website crawlable without hash symbol?

In GWT we need to use # in a URL to navigate from one page to another i.e for creating history for eg. www.abc.com/#questions/10245857 but due to which I am facing a problem in sharing the url. Google scrappers are reading the url only before # i.e. www.abc.com.
Now I want to remove # from my url and want to keep it straight as www.abc.com/question/10245857.
I am unable to do so. How can I do this?
When user navigates the app I use the hash urls and History object (as
to not reload the pages). However sometimes it's nice/needed to have a
pretty URL (e.g. for sharing, showing in public, etc..) so I would like to know how to
provide the pretty URL of the same page.
Note:
We have to do this to make our webpages url crawlable and to link the website with outside world.
There are 3 issues here, and each can be solved:
The URL should appear prettier to the user
Going directly to the pretty URL should work.
WebCrawlers should be able to get the content
These may all seem like the same issue, but they are quite distinct in this context.
Display Pretty URLs
Can be done with a small javascript file which uses HTML5 state methods. You can see a simple demo here, with source here. This makes all changes to "#" appear without the "#" (on modern browsers).
Relevent code from fiddle:
var stateObj = {locationHash: hash};
history.replaceState(stateObj, "Page Title", baseURL + hash.substring(1));
Repsond to Pretty URLs
This is relatively simple, as long as you have a listener in GWT to load based on the "#" at page load already. You can just throw up a simple re-direct servlet which reinserts the "#" mark where it belongs when requests come in.
For a servlet, listening for the pretty URL:
if(request.getPathInfo()!=null && request.getPathInfo().length()>1){
response.sendRedirect("#" + request.getPathInfo());
return;
}
Alternatively, you can serve up your GWT app directly from this servlet, and initialize it with parameters from the URL, but there's a bit of relative-path bookkeeping to be aware of.
WebCrawlers
This is the trickiest one. Basically you can't get around having static(ish) pages here. That's not too hard if there are a finite set of simple states that you're indexing. One simple scheme is to have a separate servlet which returns the raw content you normally fetch with GWT, in minimal formatted HTML. This servlet can have a different URL pattern like "/indexing/". These wouldn't be meant for humans, just for the webcrawlers. You can attach a simple javascript in the <head> to redirect users to the pretty url once the page loads.
Here's an example for the doGet method of such a servlet:
response.setContentType("text/html;charset=UTF-8");
response.setStatus(200);
pw = response.getWriter();
pw.println("<html>");
pw.println("<head><script>");
pw.println("window.location.href='http://www.example.com/#"
+ request.getPathInfo() + "';");
pw.println("</script></head>");
pw.println("<body>");
pw.println(getRawPageContent(request.getPathInfo()));
pw.println("</body>");
pw.println("</html>");
pw.flush();
pw.close();
return;
You should then just have some links to these indexing pages hidden somewhere on your main app URL (or behind a link on your main app URL).

Wicket request mapping

I am trying to map my requests in a special way to achieve a very simple purpose.
Say the root website is abc.com and has several users. Each user has a home page, admin page, requests page, etc.
Let us assume we have users user1 and user 2
I want the urls to be coded as:
abc.com/user1/admin
abc.com/user1/home
abc.com/user1/requests
So basically abc.com/user1/home is the home page for user 1 and abc.com/user1/admin is the the admin page for user 1.
I have tried using the request mapping in wicket using named parameters etc. I can encode my URL'S as abc.com/home/user1 but I can not get the encoding I desire.
Any help is welcome.
Thanks
Anant
I'm just starting with the version 1.5 of wicket but I think the new mapping system will resolve your point quite easily :
mountPage("{userCode}/home", UserHomePage.class);
mountPage("{userCode}/admin", UserAdminPage.class);
Then, in the page you just have to retrieve the page parameter to load your model.
String userCode = pageParameter.get("userCode").toString();

Wicket: how to render page programmatically and get result as string?

I'm in the process of converting an app to use i18n/l10n on all its pages. I'm very happy with Wicket's support for this, and it's going well so far. The one tricky part I've run into is the following:
We have a text file that is used as an HTML template to send email when users perform a certain operation on the site. When the user clicks a particular link, I read in this template manually, do some text substitutions like "Dear $USERNAME", and send the result as an HTML email to the user.
In order to support the 10 or so languages we're targeting, I'll either have to maintain 10 copies of this template file, or figure out a way to render this "page" using Wicket's built-in i18n support, grab the result as a string, and then send it.
Hence my question: how can I "render" a Wicket page programmatically and get the result as a string?
I'd prefer to avoid hacks like using HttpClient if at all possible; HttpClient won't have the user's Locale, won't be automatically logged in as the user, etc., so that doesn't seem like a good solution to me.
Two article regarding to this:
Render a Wicket page to a string for HTML email
Rendering Panel to a String
Currently the only other approach was using WicketTester for that, but I do not remember details how to do that.
If you just want the raw code, here it is: (This is practically the same as the solution described in the article.)
//I assumed that you want to use the current user's session for rendering. If this isn't the case, you'll have to use a mock session
MockHttpServletRequest mockReq = new MockHttpServletRequest( WebApplication.get(), ((WebRequest)getRequest()).getHttpServletRequest().getSession(), WebApplication.get().getServletContext() );
MockHttpServletResponse mockRes = new MockHttpServletResponse( mockReq );
WebResponse res = new WebResponse(mockRes);
ServletWebRequest req = new ServletWebRequest( mockReq );
RequestCycle cycle = new WebRequestCycle( WebApplication.get(), req, res );
PageParameters pp = new PageParameters();
//add page parameters here
//Your email page should really be a bookmarkable page, but if it isn't, you can replace the request target with something that better suits your case
cycle.request( new BookmarkablePageRequestTarget( EmailPage.class, pp ));
System.out.println( mockRes.getDocument() );
For newer Wicket versions: 6.7.0 came with a new ComponentRenderer precisely for this purpose!

How do I overwrite the URL in an IE address bar using RFT?

I need to execute the following steps:
1. Start an IE browser window and open a URL (Done using StartBrowser(final string URL)
2. Start a session (done by logging in)
3. Now, I want to enter a different URL in the same browser window which has the same session.
My question is related to Step 3. How can I overwrite the URL in the existing IE window.
Note: I am using a keyword driven framework written in java.
From the IBM RFT online help: You can use the loadURL() method of the browser object.
If you do not have the browser object already 'learned' into your object map, just record a click on the browser toolbar. Then you can modify that line to be Browser_htmlBrowser().loadURL("http://stackoverflow.com");
Thanks Tom. I agree that loadURL has the implementation to do what I need.
There is one more aspect that may interest others looking at this question, i.e. the way the appropriate browser object is captured. Obviously the easist way is to use the RFT record and click way, and use the appropriate recognition properties or the other way is to implement it is find the existing browseron the fly when the method is called irrespective of recognistion properties etc which may be more useful for some scenarios or frameworks, like it is done below.
RootTestObject root = getRootTestObject();
TestObject[] testobj = root.find(atDescendant(".class", "Html.HtmlBrowser"));
BrowserTestObject bto;
bto = new BrowserTestObject(testobj[0]);
bto.loadUrl(curParamOne);

Categories

Resources