This question already has answers here:
How to loop through a HashMap in JSP?
(3 answers)
Closed 5 years ago.
How to pass linkedhashmap from java servlet to jsp using request.setatttibute() and how to use it in the jsp`
LinkedHashmap<String,Person> link = new LinkedHashmap<String,Person>()
request.settattribute("hash",link)
Now how do I get it in the jsp and make it work
Here is how you can put the request attribute and then get it.
Map link = new LinkedHashMap();
link.put("key", "value");
//put map as request attribute
request.setAttribute("hash",link);
//get map as request attribute from the request
Map link1 =(Map)request.getAttribute("hash");
Related
This question already has answers here:
How to set request encoding in Tomcat?
(2 answers)
Closed 6 years ago.
I'm calling a url like this:
http://localhost:8080/abc/income?content=%E0%B6%B8%E0%B6%9C%E0%B7%99+%E0%B6%B1%E0%B6%B8+%E0%B6%BD%E0%B6%9A%E0%B7%8A%E0%B6%B8%E0%B7%8F%E0%B6%BD%E0%B7%8A.&SOURCE_PRV=%20HTTP/1.1
and in the backend (tomcat) I'm decoding the string.
But I get the content as "??? ?? ???????" (several question marks).
How can I fix this?
The java.net.URI class can help; in the documentation of URL you find
Use one of the constructors with more than one argument, like:
URI uri = new URI(
"http",
"search.barnesandnoble.com",
"/booksearch/first book.pdf",
null);
URL url = uri.toURL();
//or String request = uri.toString();
This question already has answers here:
Servlet and path parameters like /xyz/{value}/test, how to map in web.xml?
(7 answers)
Closed 7 years ago.
I new to servlet and trying to find a way to get the values from url for example /api/v1/http://localhost:8080/getInfo/product/1/order/22 So I know how to map url getInfo in web.xml. All I am looking for a way to get the product value and order value from url. How we do this in servlet? Any direction will be very helpful.
Thanks
following the conversation, I would suggest to use
request.getPathInfo() to get any information appended to the servlet url and then parse it depending on your params names.
This question already has answers here:
Spring MVC Controller: Redirect without parameters being added to my url
(6 answers)
Closed 7 years ago.
I want to remove the parameter from url which is coming from HeaderInterceptor.java in postHandle method when I load the get method after redirect from post method.
What is written in my HeaderInterceptor.java file is
modelAndView.addObject("roleId", stu.getRoleId());
So, when I redirect from post method to get , the url which come is:
http://localhost:8080/System/StudentList.htm?roleId=23
So, here I want to remove is ?roleId=23.
Following is the code written in POST method:
String referer = request.getHeader("referer");
return "redirect:"+referer;
But I m not able to see any parameter in referer string.
The code I tried in POST method is :
RedirectView redirectview = new RedirectView("?");
redirectview.setExposeModelAttributes(false);
but it is still showing the same url with parameter.
Any help would be appreciated. Thanks :)
You can manually remove the URL parameters by calling something like
String newURL = url.substring(0, url.indexOf("?"));
This question already has answers here:
Retrieving JSON from URL on Android
(6 answers)
Closed 8 years ago.
I need to use a JSON api, but don't know how to do so. All the tutorials i have found are about parsing json from a file.
I need to make a request like this: http://expandurl.appspot.com/expand?url=http%3A%2F%2Ft.co%2FgLP0Ucg
and then it will return this
{"status": "OK", "end_url": "http://www.systemcomic.com/2011/06/27/the-system-506-office-forecast/", "redirects": 3, "urls": ["http://t.co/gLP0Ucg", "http://www.notquitewrong.com/rosscottinc/2011/06/27/the-system-506-office-forecast/", "http://www.systemcomic.com//2011/06/27/the-system-506-office-forecast/", "http://www.systemcomic.com/2011/06/27/the-system-506-office-forecast/"], "start_url": "http://t.co/gLP0Ucg"}
I just need the end_url string. How would i do this? I am also going to be doing this in a ASyncTask
For getting the JSON you need to extract it using http request and after you get the response you then parse it to get the end_url.
try this to parse end_url:
final Pattern pattern = Pattern.compile("\"end_url\": \"(.+?)\",");
final Matcher matcher = pattern.matcher(You_json_string);
matcher.find();
Log.d("end_url" , matcher.group(1));
This question already has answers here:
How do I preserve the existing query string in a mod_rewrite rule
(2 answers)
Closed 8 years ago.
We are trying to redirect bin-ends2 to wines.jsp with a number of parameters passed over to the application server. Apache is stripping the parameters off and so the application server fdoes not know what yo put in the page. The Apache config is:
RewriteRule ^/wines/bin-ends2$ http://qa2:7025/wines/wines.jsp?Form=WinesSearch&type=binends [PT]
Does anyone know how to make this work?
You need to add QSA flag to your rule when you introduce new query string parameters and would like to preserve (better say, include) existing query string.
Your rule should be
RewriteRule ^/wines/bin-ends2$ http://qa2:7025/wines/wines.jsp?Form=WinesSearch&type=binends [QSA,PT]
Useful link: http://httpd.apache.org/docs/current/rewrite/flags.html#flag_qsa