java - 与控制台相比,导航中显示的输出和实际 url 不同
问题描述
目前我面临一个问题,即控制台中输出的 URL 与导航栏中显示的实际 URL 不同。我看看我有正则表达式的值,它是正确的,但是当放入 IE 时,它是不同的。导航栏中的 URL 将仅a=test
代替a=test&c=import&f=&uid=user1
控制台中显示的 URL。我可以知道如何解决这个问题吗?谢谢。
这是它的代码。
UserID user = new UserID();
public static void main(String[] args) {
String newUrl = replaceUserID(url);
System.out.print("cmd.exe /c start iexplore -k " + newUrl);
try{
Process p = Runtime.getRuntime().exec("cmd.exe /c start iexplore " + newUrl);
try{
p.waitFor();
}
catch( InterruptedException ie ){
System.out.println("InterruptedException " + ie.getMessage());
}
InputStream err = p.getErrorStream();
int ctr = 0;
if ( (ctr = err.available()) > 0 ){
byte[] buf = new byte[ctr];
System.out.println("Process failed with error:\n" + new String(buf, 0, ctr));
}
}
catch(IOException ioe)
{
System.out.println("InterruptedException " + ioe.getMessage());
}
}
public static String checkUserID(){
String username = System.getenv("USERNAME"); //grab user login id for windows
return username;
}
public static String replaceUserID(String oldUrl) {
String params = "http://example.com?a=test&c=import&f=&uid=userid";
String username = checkUserID();
try {
Pattern p = Pattern.compile("uid=([^&%]+)");
Matcher m = p.matcher(params);
while (m.find()) {
// System.out.println(m.group(1).toString());
if(m.group(1).toString() != username) {
//replace url paremeters with correct userID.
String newUrl = params.replace(m.group(1).toString(), username);
return newUrl;
}
else {
System.out.println("The username is the same");
return params;
}
}
} catch (PatternSyntaxException ex) {
// error handling
ex.printStackTrace();
}
return oldUrl;
}
解决方案
&
对命令行有特殊的意义(concat 命令,请看这里:How do I run two commands in one line in Windows CMD?)。
您需要转义 url 或整个命令。如果我没记错的话,你需要在它周围加上双引号:"...iexplore -k \"" + newUrl + "\""
推荐阅读
- javascript - 如何使用 JavaScript (Web) 列出 Firebase 中的所有用户
- python - 在python中保存具有不同维度的numpy数组列表
- c - 如何在linux中检测命令是否是交互式的
- netflix-zuul - 尝试捕获网关超时错误并用自定义 Json 消息替换的并发症
- python - 这个f在这句话中是什么意思?
- c# - 如何在 SQL 中使用 C# 创建列
- javascript - 如果用户无权访问该功能,如何禁用 onclick 功能?
- python-3.x - Azure-sdk-for-python AKS-如何在 AKS 上升级 kubernetes
- swift - AssetReader/AssetWriter - CMSampleBuffer 和 CALayer
- javascript - 从函数 node.js 访问变量数据