【发布时间】:2013-01-05 11:20:01
【问题描述】:
我正在使用这样的 HTML 表单,
<form action="/myservlet?userid=12345" method="post" enctype="multipart/form-data">
<input type="file" name="file">
<input type="submit" value="Submit">
</form>
而这个 HTML 表单的路径例如,http://www.mywebapp.com/sample.html
在我的 servlet 中,当我使用 String url = req.getRequestURL().toString(); 并打印出字符串时,它会打印表单操作 URL http://www.mywebapp.com/myservlet?userid=12345 而不是 HTML URL。
预期的 HTML URL:http://www.mywebapp.com/sample.html(只有我从这里请求并且我需要这个 URL)
谁能建议我如何在 servlet 中获取 HTML url 路径。
【问题讨论】:
-
您尝试使用
getRequestURI().toString();吗? -
HTML URL 是什么意思?你能得到
/myservlet?userid=12345吗? -
在此处粘贴示例字符串,您的意思是 html url 路径..以便有人帮助您。
-
@KevinEsche 如果我使用
getRequestURI().toString();我只会得到/myservlet我期待得到http://www.mywebapp.com/sample.html -
@sp00m 不希望得到
http://www.mywebapp.com/sample.html