怎样能把浏览器地址栏中正确的路径弄错乱码
比如说"http://localhost:8084/LabSite/NewJplusServlet.jsp?mode=SHOWLIST&page=1
把它用URLEncoder.encode("http://localhost:8084/LabSite/NewJplusServlet.jsp?mode=SHOWLIST&page=1","UTF-8")变成乱码 然后放到浏览器地址栏中 然后再后台解码进行操作,怎么实现 求大神指导
[解决办法]
你想问的是什么解码吗?可以用URLDecoder.decode()方法
[解决办法]
你在超链接里面的url加密,后台解密这个url请求就行了
[解决办法]
你是想说以这样post的方式提交请求么?
public static void main(String[] args) {
URL url = null;
HttpURLConnection httpurlconnection = null;
try {
url = new URL("http://www.ip138.com/ips.asp");
httpurlconnection = (HttpURLConnection) url.openConnection();
httpurlconnection.setDoInput(true);
httpurlconnection.setDoOutput(true);
httpurlconnection.setRequestMethod("POST");
httpurlconnection.setRequestProperty("Content-Type",
"application/x-www-form-urlencoded");
String username = "ip=192.168.0.1";
httpurlconnection.getOutputStream().write(username.getBytes());
httpurlconnection.getOutputStream().flush();
httpurlconnection.getOutputStream().close();
int code = httpurlconnection.getResponseCode();
System.out.println("code " + code);
if (code == 200) {
String cookie = httpurlconnection.getHeaderField("Set-Cookie ");
System.out.println(cookie);
// httpurlconnection.setRequestProperty( "Cookie", cookie);
DataInputStream in = new DataInputStream(httpurlconnection
.getInputStream());
int len = in.available();
byte[] by = new byte[len];
in.readFully(by);
String rev = new String(by);
System.out.println(rev);
in.close();
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (httpurlconnection != null) {
httpurlconnection.disconnect();
}
}
}