Tôi đề xuất y để sử dụng GWT MVP. Giả sử rằng url của bạn như
http://www.myPageName/myproject.html?#orderId:99999
Và trong AppController.java bạn -
Hãy thử như
......
public final void onValueChange(final ValueChangeEvent<String> event) {
String token = event.getValue();
if (token != null) {
String[] tokens = History.getToken().split(":");
final String token1 = tokens[0];
final String token2 = tokens.length > 1 ? tokens[1] : "";
if (token1.equals("orderId") && tonken2.length > 0) {
Long orderId = Long.parseLong(token2);
// another your operation
}
}
}
...........
Một lựa chọn khác, bạn cũng có thể sử dụng với Spring MVC. Dưới đây là một ví dụ ...
// Below is in your view.java or presenter.java
Window.open(GWT.getHostPageBaseURL() + "customer/order/balance.html?&orderId=99999",
"_self", "enable");
// Below code in in your serverside controller.java
@Controller
@RequestMapping("/customer")
public class ServletController {
@RequestMapping(value = "/order/balance.html", method = RequestMethod.GET)
public void downloadAuctionWonExcel(@RequestParam(value = "orderId", required = true) final String orderId,
final HttpServletResponse res) throws Exception {
try {
System.out.println("Order Id is "+orderId);
// more of your service codes
}
catch (Exception ex) {
ex.printStackTrace();
}
}
}
Tôi đang làm việc trên một vấn đề tương tự, làm cách nào để ứng dụng trả lời thông số như, orderID = 99999? Tôi có nghĩa là nó xử lý các tham số như thế nào? – xybrek
@xybrek Nếu bạn không xem xét [Cơ chế lịch sử] được cung cấp (http://www.gwtproject.org/doc/latest/DevGuideCodingBasicsHistory.html) trong GWT (sử dụng # để tránh tải lại trang), bạn sẽ cần đặt một phương thức trong điểm vào chính của bạn, được gọi trong phương thức 'onLoad()' của điểm vào chính.Mỗi lần trang được gọi nó sẽ gọi phương thức chuyên dụng của bạn, trong đó bạn có thể kiểm tra và xử lý các tham số đã cho. – Dennis