I have the following issue:
I'm using Spring-MVC with JSPs.
On my page I want to put a couple of links(with urls) in the content area. I'm getting the names of the links plus the description from a properties file via spring:messages.
Now the question is, what is the best-practice or most elegant way to put the link-urls on the page. Should I hardcode them in the jsp? Should they come from the properties file where I have stored the text which goes on the page, should they come from the controller (where they would be stored in static variables) or should they be passed through all the way using a service and a bean etc.?
I would appreciate your opinion!
Related
As per the html the source code is:
{result.data}
While requesting the URL result.data is set with 100 and am able to see the value as 100 in the browser. Where as while I am trying to execute the java program with the same url request I am unable to see the value as I have seen in browser.
URL url = new URL(site)
url.openConnection() etc..
I wanted to get the same content as I have seen in the browser through java program.
Your question is not very descriptive, but I guess you are trying to scrape data from the site.
You can use the following libraries for this task:
Jaunt (http://jaunt-api.com)
Jsoup (http://jsoup.org/cookbook/extracting-data/dom-navigation)
HTMLUnit
To what i understand, you want to do one of the below things :
Instead of reading the result line by line, you want to parse it as an XML to as to traverse to div(s) and other html tags.
For this purpose i would suggest you to use jsoup library.
When you hit the URL: www.abcd.com/number=500 in browser, it loads an empty div and on load it fetches data from somewhere, this data which it fetches on load, you want to fetch this using java ?
For this, there must be some js in the resulting page, which is fetching data by hitting some service on page load, you will need to look up in the page to know the service details and instead of hitting this URL (www.abcd.com/number=500) you will need to hit that service to get data.
I am trying to create a JSON response but I need some things that is easily done in ISML. First I would like to know how I can build a proper URL this should link to a pipeline call with some parameters. The other thing I would like to know is how can I access language property files in a pipelet/java like the istext tag that you can call with ISML
Thank you
If you do not like to use the URL with the pipeline name, you can create a short URL in the back office, or create a URL rewrite rule.
Every parameter you add to the URL will of course be available in the pipeline dictionary.
To get a localized text in Java take a look at the GetLocalizedTextByKey pipelet.
It uses the LocalizationProvider to provide a localized text for a specific key and a locale.
You can also take a look at this Intershop Knowledge Base article if you have access: https://support.intershop.com/kb/index.php/Display/2258M5
I am trying to serve a static html file let's call it index.html for all dynamic urls like /tachyon/someId. This someId is generated dynamically. I have tried multiple ways to do this but all failed. This is what all I have tried.
Tried adding controllers.Assets.at(path="/public", file="index.html") for GET url /tachyon/*someId. This failed saying missing parameter someId.
Tried rendering index.html through render. This also failed since index.html is not a scala.html template.
Tried returning routes.Assets.at("index.html") through controller. This also failed since I want to return Result but the return type for the method is different.
Tried returning ok(routes.Assets.at("index.html") through controller. This also failed saying not a valid Call for ok.
It would be better if there is a way to do this through controller and returning Result from method in task helper class to task since I am returning Promise<Result> from method in task class.
I think you can use Twirl to generate the page. Since you want a static html, you can ignore the parameter in the body.
so in routes, add:
GET /tachyon/*someId somecontroller.index(someId)
in the controller's index function, you can return
Ok(views.html.somepage(someId))
And you create a somepage.scala.html Twirl function in views folder, but do not use someId in the body.
I got it working. Not sure if it is the correct solution or not. I rendered the index.html by converting it to a byte array and then using ok to render using ByteArrayInputStream. Something like this.
File file = Play.getFile("path to the file", Play.current());
byte[] byteArray = IOUtils.toByteArray(new FileInputStream(file));
return ok(new ByteArrayInputStream(byteArray)).as("text/html");
Let me know if there is any better way to do this without using scala templating.
Thanks
I'd like to change the URL of some pages in my website in the same way as foursquare is doing:
from www.foursquare.com/v/anystring/venueid
to www.foursquare.com/v/venue-name/venueid
For example central park in new york:
https://foursquare.com/v/writeherewhatyouwant/412d2800f964a520df0c1fe3
becomes
https://foursquare.com/v/central-park/412d2800f964a520df0c1fe3
I'm developing a pure JSP/Servlet app, no frameworks, in a Tomcat container.
I'm thought of using tuckey's urlrewritefilter, but I don't see how can I use dynamic values coming from the servlet itself there (the venue name)
How can I accomplish this?
Off the top of my head, here's something you could try:
1) Create a servlet with a servlet-mapping matching the common (prefix) part of the URL (e.g. for foursquare the pattern would be /v/*).
2) In your servlet, retrieve the remaining part of the URL path using request.getPathInfo(). You can then parse it using regular string utilities and convert it to the new path you'd like.
3) Assuming your updated path is in a variable called newUrl, call response.sendRedirect(newUrl) to tell the browser to update its URL. This will also call your servlet again with the new path, so it needs to handle both cases.
See the javadoc for HttpServletResponse.sendRedirect() for more info about how it handles relative vs absolute paths, etc.
This is a struts2 question.
Currently, I am using i18n for internationalization in my webapp.
Some of my jsp pages has querystring to store the request information.
For example,
http://myWebsite.com/myWebsite/myPage?productId=12345
When users try to switch language, I rewrite the URL by javascript to
http://myWebsite.com/myWebsite/myPage?request_locale=zh_CN
And it loses the query string.
And my urls are used in different ways:
http://myWebsite.com/myWebsite/myPage
http://myWebsite.com/myWebsite/myPage?productId=12345#myAnchor
http://myWebsite.com/myWebsite/myPage?productId=12345&key2=value2&key3=value3#myAnchor
http://myWebsite.com/myWebsite/myPage?productId=12345&key2=value2&key3=value3&request_locale=zh_CN
http://myWebsite.com/myWebsite/myPage?productId=12345&key2=value2&key3=value3
...
When I try to handle all this differences in javascript, it becomes so complicated.
Is there any good way to retain the querystrings and anchors after switching locale?
When you rewrite the URL using JS, you should do it based on the current URL.
So, if in the browser is showed
http://myWebsite.com/myWebsite/myPage?productId=12345
you should rewrite it as
http://myWebsite.com/myWebsite/myPage?productId=12345&request_locale=zh_CN
For that, using JS you should get the current URL displayed. Take a look to this question for how to.