I am trying to read a url which is throwing a string. I am storing that string in some variable and trying to print that variable on my web page using jsp. When I print my string on my web page it is giving some junk characters. How can I get the original string?
Here is my jsp code:
Market.jsp
<%@page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<%
URL url;
ArrayList<String> list1 = new ArrayList<String>();
ArrayList<String> list2 = new ArrayList<String>();
List commodity1 = null;
List price1 = null;
int c, p = 0;
try {
// get URL content
String a = "http://122.160.81.37:8080/mandim/MarketWise?m=agra";
url = new URL(a);
URLConnection conn = url.openConnection();
// open the stream and put it into BufferedReader
BufferedReader br = new BufferedReader(
new InputStreamReader(conn.getInputStream()));
StringBuffer sb = new StringBuffer();
String inputLine;
while ((inputLine = br.readLine()) != null) {
System.out.println(inputLine);
// sb.append(inputLine);
String s = inputLine.replace("|", "\n");
s = s.replace("~", " ");
StringTokenizer str = new StringTokenizer(s);
while (str.hasMoreTokens())
{
String mandi = str.nextElement().toString();
String price = str.nextElement().toString();
list1.add(mandi);
list2.add(price);
}
}
commodity1 = list1.subList(0, 10);
// commodity10=list1.subList(90,100);
price1 = list2.subList(0, 10);
int c1 = 0;
int p1 = 0;
for (c1 = 0, p1 = 0; c1 < commodity1.size() && p1 < price1.size(); c1++, p1++) {
String x = (String) commodity1.get(c1);
String y = (String) price1.get(p1);
out.println(x);
out.println(y);
}
br.close();
//System.out.println(sb);
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
%>
</body>
</html>
I am getting the following output
धान 1325 चावल 2050 ज�वर 920 जौ 810 मकई 1280 गेहू� 1420 जो 1050 बेजर - जय 800 उड़द 3600
How can I achieve my desired goal?
Thanks in advance