我正在尝试验证从 URL 传递的一些值。我正在尝试在 UI 中获取这些值,但不起作用。
我正在尝试这个。
// link send by email, click to validate
String url = "http://localhost:8080/MyProject/ValidateValues?NAME=FERNANDO&AGE=34"
// ValidateValues UI class
public class ValidateValues extends UI{
@Override
protected void init(VaadinRequest request) {
String name = request.getParameter("NAME");
String age = request.getParameter("AGE");
System.out.println(name);
System.out.println(age);
}
}
有什么想法吗?
最佳答案
以下代码提供了一个可行的解决方案:
String sPathInfo = request.getPathInfo();
if ("/ValidateValues".equals(sPathInfo)) {
// TODO: Check if NAME and AGE are contained in the ParameterMap!
String sName = request.getParameterMap().get("NAME")[0];
String sAge = request.getParameterMap().get("AGE")[0];
Notification.show(String.format("Name: %s Age: %s", sName, sAge));
}
else {
// not correct path
}
关于java - 获取当前值 URL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20611803/