如果我理解正确,您希望通过POST-GET方法将身份验证凭据(或有效身份验证)传递给java applet中的vaadin web应用程序。
我还没有管理小应用程序,但如果你想从java做它(我认为你需要的唯一的额外的东西是在你的构建路径或lib WEB-INF目录中包含apache-commons库它工作),你必须从java applet到你的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代替,但它仍然不安全,因为请愿书可以通过“中间人”阅读,所以您必须至少对其进行加密以防止某种注射。