「java中表单怎么提交」java创建表单

博主:adminadmin 2022-11-30 13:26:07 43

本篇文章给大家谈谈java中表单怎么提交,以及java创建表单对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。

本文目录一览:

JAVA如何提交表单

界面上有个东西叫form的,form里面有个按钮类型是submit,

一般名字都叫提交,确定,查询之类的,你按了这个按钮后,他会自己去找form中action所对应的selvet(这个selvet在web-inf.xml中配置好了的),selvet中再调用相关的方法,查询出数据后,通过 request的request.setAttr...方法,数据传递到页面上去,这样你就看到了结果

其实这个是基本的mvc模式了

看你最后一句,你好像是说用j2se来发送和取得信息,也是可以的.那就要用流了,用j2ee就不用考虑他们是怎么传的,只要知道如何传就可以了.

怎么用Java模拟form表单提交

用Java模拟form表单提交的方法,在struts2中的配置如下:

!-- action属性为actionNmae!methodName的形式

其中ActionName指定提交到哪个Action,而methodName指定提交到指定方法--

action="ActionName!add"

其中一个按钮的代码如下:

input type="submit" value="注册" onclick="regist();" /

点击“注册”按钮被单击时触发regist函数,该函数的代码如下:

script type="text/javascript"

function regist(){

targetForm = document.forms[0];

targetForm.action = "login!add";

}

/script

java面试问项目中的表单是怎样提交的

关于获取提交的表单数据可以采用以下方法,例如:

控制层相关代码:request.getParameter("userName");

(注:userName是from表单中name属性的值)

java 提交表单

实现代码如下:

public class Demo {

public static void main(String[] args) throws Exception {

Map m = new HashMap();

String url = "";

String code = "GB2312";

// m.put("sel_zazhimc", "");

//

// m.put("sel_niandu", "");

//

// m.put("txt_qishiye", "");

//

// m.put("txt_doi", "");

// m.put("xueke", "");

// m.put("zhuanye", "");

// m.put("txt_zuozhe", "");

// m.put("txt_zuozhe2", "");

// m.put("txt_zuozhedw", "");

//

// m.put("txt_zhaiyao", "");

// m.put("txt_guanjianci", "");

// m.put("txt_fenleihao", "");

// m.put("sel_niandus", "");

// m.put("sel_niandue", "");

m.put("txt_wenti", "数据");

m.put("pagesize", "10");

m.put("Submit2", "查询");

m.put("rad_px", "zuozhexm,kanchurq desc");

String rus = doPost(url, m, code);

System.out.println(rus);

}

public static String doPost(String reqUrl, Map parameters, String recvEncoding) {

HttpURLConnection conn = null;

String responseContent = null;

try {

StringBuffer params = new StringBuffer();

for (Iterator iter = parameters.entrySet().iterator(); iter.hasNext();) {

Entry element = (Entry) iter.next();

params.append(element.getKey().toString());

params.append("=");

params.append(URLEncoder.encode(element.getValue().toString(), recvEncoding));

params.append("");

}

if (params.length() 0) {

params = params.deleteCharAt(params.length() - 1);

}

URL url = new URL(reqUrl);

HttpURLConnection url_con = (HttpURLConnection) url.openConnection();

url_con.setRequestMethod("POST");

// System.setProperty("sun.net.client.defaultConnectTimeout", String

// .valueOf(HttpRequestProxy.connectTimeOut));// (单位:毫秒)jdk1.4换成这个,连接超时

// System.setProperty("sun.net.client.defaultReadTimeout", String

// .valueOf(HttpRequestProxy.readTimeOut)); // (单位:毫秒)jdk1.4换成这个,读操作超时

url_con.setConnectTimeout(5000);//(单位:毫秒)jdk

// 1.5换成这个,连接超时

url_con.setReadTimeout(5000);//(单位:毫秒)jdk 1.5换成这个,读操作超时

url_con.setDoOutput(true);

byte[] b = params.toString().getBytes();

url_con.getOutputStream().write(b, 0, b.length);

url_con.getOutputStream().flush();

url_con.getOutputStream().close();

InputStream in = url_con.getInputStream();

BufferedReader rd = new BufferedReader(new InputStreamReader(in, recvEncoding));

String tempLine = rd.readLine();

StringBuffer tempStr = new StringBuffer();

String crlf = System.getProperty("line.separator");

while (tempLine != null) {

tempStr.append(tempLine);

tempStr.append(crlf);

tempLine = rd.readLine();

}

responseContent = tempStr.toString();

rd.close();

in.close();

} catch (IOException e) {

e.printStackTrace();

} finally {

if (conn != null) {

conn.disconnect();

}

}

return responseContent;

}

}

java 中为什么提交表单用submit! form的onsubmit属性具体怎么来提交表单的?

表单数据用submit提交到后台,这个不能问为什么。

onsubmit

事件会在表单中的确认按钮被点击时发生。然后你可以在onsubmit里写js代码,比如用来校验表单数据

在java中写jsp网页和servlet中,form表单的提交方法get与post的区别

get是默认提交方式,如果不在method方法中声明,表单会议get方式提交到服务器,提交的数据信息会显示在浏览器栏地址栏内,Post方式提交表单后的地址栏不变 。doGet和doPost对应其form的mothod属性Get和Post。Get方式提交来的数据在服务器端用Request.QueryString()来获取,用Post方式提交的数据用Request.Form()来获取,但默认还是可以用request()获得

利用get方法提交的内容不能超过2kb,否则提交会失败,

post无限制

关于java中表单怎么提交和java创建表单的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。

The End

发布于:2022-11-30,除非注明,否则均为首码项目网原创文章,转载请注明出处。