0

私はこの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="button" に設定したので、リダイレクトはありませんが、それでもメソッドは実行されません。

何か案は?

4

1 に答える 1

2

タグのデフォルトの動作と同様に、type="button"属性を変更するtype="submit"か、単に削除します。通常、クライアント側のメソッドまたは Ajax 呼び出しを実行するために使用されます。BalusC による別の投稿があります。type="submit"type="button"

于 2013-07-12T21:12:24.263 に答える