首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >CommandButton问题

CommandButton问题
EN

Stack Overflow用户
提问于 2013-07-12 06:17:04
回答 1查看 83关注 0票数 0

我有这个JSF代码

代码语言:javascript
复制
<f:view>
    <h:form>
        <h:commandButton value="Submit info" type="button" action="#{bean.submit}" />
    </h:form>
</f:view>

我也有这个豆子

代码语言:javascript
复制
@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=”,所以没有重定向,但仍然不会执行该方法。

有什么想法吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-07-13 05:12:24

更改type="submit"type="button"属性或将其删除,因为type="submit"是标记的默认行为。type="button"通常用于execute client side methods或Ajax调用。这里有another post by BalusC

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17604480

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档