我有这个 JSF 代码
<f:view>
<h:form>
<h:commandButton value="Submit info" type="button" action="#{bean.submit}" />
</h:form>
</f:view>
我也有这个豆子
@ManagedBean(name="bean")
@RequestScoped
public class Bean{
public void submit(){
HttpURLConnection connection = null;
URL url;
String generatedUrl = "blalabla"; //Long url
StringBuffer response = new StringBuffer();
try {
url = new URL(generatedUrl);
connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
int responseCode = connection.getResponseCode();
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String inputLine;
while((inputLine = in.readLine()) != null){
response.append(inputLine);
}
in.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
当我单击按钮时,不执行提交方法。似乎按钮没有做任何事情。由于我将其设置为 type="button",因此没有重定向,但仍然没有执行该方法。
有任何想法吗?