Hi,
Do you know any JDK service in Java 1.5 that knows to take care of URL appending? (taking care of putting "?" or "&" depends on the fact that the query param is the first one or not).
Thanks, Shay
Hi,
Do you know any JDK service in Java 1.5 that knows to take care of URL appending? (taking care of putting "?" or "&" depends on the fact that the query param is the first one or not).
Thanks, Shay
public String buildUrl(String url, List<String> params) {
StringBuilder builder = new StringBuilder(url);
if(params != null && params.size() > 0) {
builder.append("?");
for(Iterator<String> i = params.iterator(); i.hasNext();) {
String s = i.next();
builder.append(s);
if(i.hasNext()) {
builder.append("&");
}
}
}
return builder.toString();
}
As far as I know, there's one called JavaService
which allows server-type Java Programs to run on Windows platform. I don't know whether it could satisfy your need.
There's an alternative way that you can code the functionality for your necessity, then make it as a Windows Service
. I've once read an article at DevX and an article titled Running Java Applications as a Windows Service.
A rather straightforward (and very similar to Noel M's example who posted it while I'm writing) way would be:
StringBuilder sb = new StringBuilder(url);
url.indexOf("?") > -1 ? sb.append("&") : sb.append("?");
// loop over your paramaters and append them like in Noel M's example
url = sb.toString();