如果我理解正确,您想通过带有身份验证凭据(或有效身份验证)的 POST-GET 方法将数据从 java applet 传递给 vaadin Web 应用程序。
我没有管理小程序,但是如果您想从 java 中进行操作(我认为您唯一需要做的就是在构建路径或 lib WEB-INF 目录中包含 apache-commons 库以使其工作)您必须从 Java 小程序向您的 vaadin Web 应用程序发出 HTTP GET/POST 请求。给出的例子:
/* FROM JAVA APPLET EXECUTE JSON GET */
public static String getJson(String parameter) throws ClientProtocolException, IOException {
String url = "http://somedomain.com/VaadinApp?parameter=";
String resp="";
HttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet(url + parameter); // here you put the entire URL with the GET parameters
HttpResponse response = client.execute(request);
// from here is postprocessing to handle the response, in my case JSON
BufferedReader rd = new BufferedReader (new InputStreamReader(response.getEntity().getContent()));
String line = "";
StringBuilder sb = new StringBuilder("");
while ((line = rd.readLine()) != null) {
sb.append(line);
}
// if defined, this will return the response of the vaadin application, for this example no response is given from the server
return sb.toString();
}
然后,在您的 vaadin 应用程序中,您可以通过 Vaadin 请求处理 GET/POST 参数,在这种情况下,从您的主 UI:
public class VaadinApp extends UI {
@WebServlet(value = "/*", asyncSupported = true)
@VaadinServletConfiguration(productionMode = false, ui = VaadinApp.class)
public static class Servlet extends VaadinServlet {
}
VistaPrincipal vp;
@Override
protected void init(VaadinRequest request) {
final VerticalLayout layout = new VerticalLayout();
VistaPrincipal vp = null;
vp = new VistaPrincipal();
if(request.getParameter("parameter") != null) {
Notification.show("Success");
// show the parameter in GET request
System.out.println("parameter:" + request.getParameter("parameter"));
}
layout.addComponent(vp);
layout.setComponentAlignment(vp, Alignment.TOP_CENTER);
layout.setMargin(false);
setContent(layout);
}
}
HttpRequest 可以通过多种方式进行,但在通过 GET 发送参数时要小心,因为它们会显示在 URL 中。您可以改用 POST,但它仍然不安全,因为“中间人”可以读取请愿书,因此您至少必须对其进行加密以防止某种注入。