使用ApacheWicket,微格式化是如何工作的



我想使用ApacheWicket实现微平台体系结构,但我无法实现。

add(new WebMarkupContainer("testFrame") {
@Override
protected void onComponentTag(ComponentTag tag) {
checkComponentTag(tag, "iframe");
super.onComponentTag(tag);
//Won't work like this if you want to send credentials.
//tag.put("src", "http://localhost:8089/httpBasicAuthenticated/url/page/");
}
@Override
public void onComponentTagBody(MarkupStream markupStream, ComponentTag openTag) {
Response response = getRequestCycle().getResponse();
final CredentialsProvider provider = new BasicCredentialsProvider();
String username = "user";
String password = "password";
final UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(username, password);
provider.setCredentials(AuthScope.ANY, credentials);
final HttpClient client = HttpClientBuilder.create().setDefaultCredentialsProvider(provider).build();
HttpResponse httpResponse = null;
String body = "";
try {
httpResponse = client.execute(new 
HttpGet("http://localhost:8089/httpBasicAuthenticated/url/page/"));
body = IOUtils.toString(httpResponse.getEntity().getContent(), "UTF-8");
} catch (final IOException e) {
e.printStackTrace();
}
response.write(body);
}
});

元件检查结果

我正在尝试使用iframe,但它没有在iframe中呈现页面。有什么问题吗?我将如何通过iframe根据页面请求发送凭据?

编辑:在这段代码中,我试图自动发送凭据,这样就不会显示身份验证提示。

使用基本身份验证,您需要呈现<iframe src="..."></iframe>,浏览器将显示一个对话框来输入凭据。

如果您在服务器上构造主体(即在Wicket代码中(,那么您不需要iframe,而是需要div

相关内容

  • 没有找到相关文章

最新更新