我有这样的网址:
http://test.com/testapp/test.do?test_id=1&test_name=SS
有什么办法我们只能得到这部分
/test.do?test_id=1&test_name=SS
我有这样的网址:
http://test.com/testapp/test.do?test_id=1&test_name=SS
有什么办法我们只能得到这部分
/test.do?test_id=1&test_name=SS
用于java.net.URL
解析 url 字符串:
URL url = new URL("http://test.com/testapp/test.do?test_id=1&test_name=SS");
System.out.println(url.getPath()+"?"+url.getQuery());
在你的 ActionClass 里面
String actionName = (String)ActionContext.getContext().get(ActionContext.ACTION_NAME);
会给你“测试”。
HttpServletRequest request = ServletActionContext.getRequest();
是您的 servlet 请求,您可以从哪里获取所有参数。无论如何,看看ActionContext.getContext()。你可以从那里得到很多东西。希望这可以帮助。
不是真正的 URL 解析,但这会做你的工作:
String[] parts = "http://test.com/testapp/test.dotest_id=1&test_name=SS".split("/");
return "/"+parts[parts.length-1]