我不断收到这个错误,我真的不知道为什么。我尝试过不同的网址,但我仍然遇到同样的错误。
java.net.MalformedURLException
java.net.URL。(未知来源)
public class ProxyServlet extends HttpServlet {
private String PostUrl = "http://localhost:8080/myProxy/myServlet";
private static final long serialVersionUID = 1L;
public ProxyServlet() {
super();
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
System.out.println("Parameters retreived...");
// map parameters to properties in config file and set response
Map();
}
private void Map() throws IOException{
String urlParameters = "topic="+topic+"&item="+item+"&period="+period+";
URL url = new URL(PostUrl);
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
System.out.println("Connection made to " + PostUrl);
conn.setDoOutput(true);
conn.setInstanceFollowRedirects(true);
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
conn.setRequestProperty("charset", "utf-8");
OutputStream out = null;
try{
System.out.println("Writing data to output stream...");
out = conn.getOutputStream();
out.write(urlParameters.getBytes());
out.close();
System.out.println("All done!!!");
}
catch(IOException e){
e.printStackTrace();
}
}
}任何帮助,将不胜感激!!
谢谢!