如何从jsp页面上的url读取文本

时间:2014-04-26 12:08:29

标签: java jsp url

嗨我正在尝试从网址读取文本,当我尝试收集网址时,它会打印一些其他文本代替原始文本原始文本在印地文中如何获得我的输出

这是我的代码

   <section>
    <div class="push">

     <table  width="100%" border="1" align="center" cellpadding="0" cellspacing="1" bordercolor='66A8FF'>
     <%

       URL url;
        try {
            // get URL content

            String a="http://122.160.81.37:8080/mandic/commoditywise?c=paddy";
            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);

                   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();


    %>
     <tr bgcolor="0F57FF" style="border-collapse:collapse">
        <td width="50%" height="50px" align="center" style="font-size:24px;"><font color="#fff"><%= mandi%></font></td>
    <td  width="50%"  height="50px" align="center" style="font-size:24px"><font color="#fff"><%= price%></font></td>
  </tr>
    <%
}
            }
            br.close();

            //System.out.println(sb);

        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }    

       %>

     </table>
    </div>
        </section> 

我在输出中得到这个

अचà¥à¤›à¤¨à¥‡à¤°à¤¾  NIL
आगरा  NIL
फ़तेहाबाठNIL

这是我提供正确输出的简单代码

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.StringTokenizer;

public class URLConetent{
    public static void main(String[] args) {

        URL url;

        try {
            // get URL content

            String a="http://122.160.81.37:8080/mandic/commoditywise?c=paddy";
            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("~"," ");
                    //System.out.println(s);
                    StringTokenizer str = new StringTokenizer(s);
                    while(str.hasMoreTokens())
     // for(int i=0;i<s.length;i++)
  // if(str.hasMoreElements())
   {
       String mandi = str.nextElement().toString();

          String price = str.nextElement().toString();
          System.out.println("MANDI"+mandi);
          System.out.println("Price"+price);
    }
            }
            br.close();

            //System.out.println(sb);

        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}

Thanks in advance

0 个答案:

没有答案