我有这个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();
}
}
}当我单击该按钮时,不会执行submit方法。这个按钮好像什么也做不了。由于我将其设置为按钮“type=”,所以没有重定向,但仍然不会执行该方法。
有什么想法吗?
发布于 2013-07-13 05:12:24
更改type="submit"的type="button"属性或将其删除,因为type="submit"是标记的默认行为。type="button"通常用于execute client side methods或Ajax调用。这里有another post by BalusC。
https://stackoverflow.com/questions/17604480
复制相似问题