URL without hash (#) in GWT - java

In GWT i need to use # in URL, in order to navigate from one page to another for eg. www.abc.com/#questions/10245857 but due to which i am facing 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. Please help me with some links or code.
Thank you

If you want URLs that don't use the hash, then you have to use HTML5 pushState (browser compatibility).
You cannot do that if you use the History class directly; you'd have to create your own History class that use pushState and use that class in your code instead of the GWT built-in one.
If you use Places, then it's much easier as all you have to do is implement an Historian rather than use the DefaultHistorian; e.g. https://gist.github.com/tbroyer/1883821
If you need to support browsers that don't have pushState, then things get much more complex.
There are alternatives though:
you can use #! and implement the necessary server-side hooks: https://developers.google.com/webmasters/ajax-crawling/ (there are projects that implement this by running your GWT app within an HTMLUnit pseudo-browser on the server; IIRC, GWT-Platform has such a feature)
you can provide permalinks to your "places", like Google Maps or Google Groups do; see https://stackoverflow.com/a/24717441/116472

The # represents places inside the application so to change the URL try Creating different GWT entry point modules could solve this issue – there would be only one web application this time, but each module would be accessible via a different URL. Look into this article http://www.summa-tech.com/blog/2011/02/22/structuring-gwt-modules-for-large-applications/

Related

Identifying Java desktop client dependencies for web apps

We have a set of web apps and want to identify if they have a Java client-side dependency i.e. if they invoke the client installed JRE.
Is there an easy way to do this? or do we have to manually scan the code for or anything else that may have a Java client dependency?
Thanks.
No, there is no easy way to do this.
It would be easy if all your web-apps would use a <applet> html tag or a <object> html tag, then you could simply match every html source. This you can do anyway to find some of the web-apps that use java, at least on the start page of the app.
But since it is also possible to load java applets using javascript and an automatism cannot navigate through an app like a user, there is no easy way to do this.
If you have control over the clients (e.g. company internal), you might turn off java on a few clients and let the users do the checking (e.g. they will call if something does not work). Maybe you even have key users for application tests.

How to generate different HTML based on the device that access the page?

I am using Java EE 6 with all the reference implementations and I wonder how you can generate different responses based on the device accessing the page? At the moment when I develop a JSF page I target browsers running on PC. However I want to generate another HTML structure (that is, using another JSF page) when the user browses the page with a smart phone.
Now you wonder, "Why doesn't you use CSS media queries?". Yes, I could but that will only give limited control over the layout. Could someone give me some hints to where and what to start reading about to do this?
I don't want to use Spring, I know they have something like this.
I don't want to use Spring, I know they have something like this.
Just reinvent it then (cough).
Let's look how they did it. According to the Spring Mobile documentation, cited below,
LiteDeviceResolver
The default DeviceResolver implementation is based on the "lite" detection algorithm implemented as part of the Wordpress Mobile Pack. This resolver only detects the presence of a mobile device and does not detect specific capabilities. No special configuration is required to enable this resolver, simply configure a default DeviceResolverHandlerInterceptor and it will be enabled for you.
it seems that they have ported this piece of PHP code to this piece of Java code. You could just do the same (be aware of license rules!). The most sensible place for this would be a servlet filter which would then send a redirect depending on the outcome of the detection.
I think you will need to look to the HTTP_USER_AGENT.
No experience with Java, but look to System.getEnv("HTTP_USER_AGENT").
It should return a string name for the user agent. You should find in the web lists of common user agents, so you can easily classify them as mobile or not mobile.
Inspect HTTP header
user-agent
you can retrieve this using Servlet API: http://docs.oracle.com/javaee/6/api/javax/servlet/http/HttpServletRequest.html#getHeader%28java.lang.String%29

How Can I rewrite SEO friendly URL on STRUTS?

We have a website which is coded Java with Struts Framework. The WebSite's Urls are not seo friendly. All of them are like below
../buyerApplication.do&companyId=2323
Now We want to make these URLs SEO friendly and I searched and found these solutions:
tuckey.org/urlrewrite : but i don't rely on this system.
adding
title end of link after '&' such as
"../newsId=33233&does-art-in-the-city-equal-art-for-the-city"
: In this solution I am not sure it
works well.
I am waiting your sugestions to solve this problem best.
I actually used URLRewriter (http://tuckey.org/urlrewrite/), which you referenced in your original question. It was very easy to set up and filled my needs perfectly.
To the point, you need a Filter for this.
If you want to keep your existing application's architecture, you'll need to define and create a set of rules to convert unfriendly urls to friendly urls and let the filter convert it and forward the request to the unfriendly url.
If there is no means of modifying an existing application but you want to create a new application based on this idea, you could consider to having a single page controller which translates the HttpServletRequest#getPathInfo()/getRequestURI() to execute the appropriate action class (command pattern) and finally forward the request to the appropriate JSP page. Not sure how that would fit into Struts as I haven't worked with Struts previously.
For what it's worth, you can also look at the REST plugin http://struts.apache.org/2.x/docs/rest-plugin.html, which amongst other things will make your URLs more friendly

multiple sites with Java App Engine

I'm trying to create a series of sites that all run as one application, but have different designs (to localise them).
My idea is to map separate domain names to the one site. E.g: www.mysite1.com maps to www.mysite.appspot.com/mysite1 and www.mysite2.com maps to www.mysite.appspot.com/mysite2
I'm guessing that there must be a url pattern or something to pass a servlet the name of the site from web.xml? I'd like urls such as www.mysite.appspot.com/mysite1/forumpost/3/ to be able to be handled by the same servlet as www.mysite.appspot.com/mysite2/forumpost/3/.
Ideally I'd like to pass the site name as a parameter to the servlet.
Surely there is someone that has done this before, or some standard way of doing this? I've got a fuzzy idea about parsing the url to take the site name out of it, but I'm pretty new to servlets etc and thought that someone might be able to shed some light on this situation.
Thanks!
You can't map your own subdomains of appspot.com apps (eg, foo.mysite.appspot.com), but you can map arbitrary domains to your app directly, such as www.mysite1.com and www.mysite2.com - just add them all as aliases to your Google Apps account, and then map them to your App Engine app. Once you've got that done, you just need to check the content of the Host header in your app to route requests to the appropriate handlers (or otherwise vary the content you return).
Try using a javax.servlet.Filter and forwarding to the language specific pages based on the HTTP request header 'Accept-Language' (I think that's the one). You can get at that with a call to javax.servlet.HttpServletRequest.getHeader(String).
This way your site has a single URL and the separation into language specific pages is handled internally.

autogenerate HTTP screen scraping Java code

I need to screen scrape some data from a website, because it isn't available via their web service. When I've needed to do this previously, I've written the Java code myself using Apache's HTTP client library to make the relevant HTTP calls to download the data. I figured out the relevant calls I needed to make by clicking through the relevant screens in a browser while using the Charles web proxy to log the corresponding HTTP calls.
As you can imagine this is a fairly tedious process, and I'm wodering if there's a tool that can actually generate the Java code that corresponds to a browser session. I expect the generated code wouldn't be as pretty as code written manually, but I could always tidy it up afterwards. Does anyone know if such a tool exists? Selenium is one possibility I'm aware of, though I'm not sure if it supports this exact use case.
Thanks,
Don
I would also add +1 for HtmlUnit since its functionality is very powerful: if you are needing behaviour 'as though a real browser was scraping and using the page' that's definitely the best option available. HtmlUnit executes (if you want it to) the Javascript in the page.
It currently has full featured support for all the main Javascript libraries and will execute JS code using them. Corresponding with that you can get handles to the Javascript objects in page programmatically within your test.
If however the scope of what you are trying to do is less, more along the lines of reading some of the HTML elements and where you dont much care about Javascript, then using NekoHTML should suffice. Its similar to JDom giving programmatic - rather than XPath - access to the tree. You would probably need to use Apache's HttpClient to retrieve pages.
The manageability.org blog has an entry which lists a whole bunch of web page scraping tools for Java. However, I do not seem to be able to reach it right now, but I did find a text only representation in Google's cache here.
You should take a look at HtmlUnit - it was designed for testing websites but works great for screen scraping and navigating through multiple pages. It takes care of cookies and other session-related stuff.
I would say I personally like to use HtmlUnit and Selenium as my 2 favorite tools for Screen Scraping.
A tool called The Grinder allows you to script a session to a site by going through its proxy. The output is Python (runnable in Jython).

Categories

Resources