How can JAVA submit() for JSP?

Asked 2 years ago, Updated 2 years ago, 38 views

How can I replace the code below with Java?

I would appreciate your advice.

<a href="javascript:doSubmit()">Move Page</a>

function doSubmit(){
    document.form.mode.value="abc";
    document.form.action="./test.do";
    document.form.submit();
}

I tried to use the following code, but it seems that the contents of sendData cannot be sent well, so the page transition is not working well.

String sendData="mode=\"REF\"+
                      "&action=\"./test.do\";

    url = new URL ("https://www.test.com/main.do");
    con=(HttpURLConnection) url.openConnection();

    con.setDoOutput(true);
    con.setDoInput(true);
    con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded";

    os=con.getOutputStream();

    osw = new OutputStreamWriter(os, "utf-8");
    osw.write(sendData);
    osw.close();

    isr = new InputStreamReader(con.getInputStream(), "utf-8");
    br = new BufferedReader(isr);
    String line = null;
    while((line=br.readLine())!=null){
           response+=line;
    }

java

2022-09-30 20:21

1 Answers

HttpURLConnection#connect() will actually connect you, so try adding con.connect() after osw.close().


2022-09-30 20:21

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.