String?temp?=?"form?name='form1'?method='post'?action='null'input?type='hidden'?name='Retdesc'?value='parameters?error'/formscriptdocument.form1.submit();/script";
站在用戶的角度思考問題,與客戶深入溝通,找到同心網(wǎng)站設(shè)計(jì)與同心網(wǎng)站推廣的解決方案,憑借多年的經(jīng)驗(yàn),讓設(shè)計(jì)與互聯(lián)網(wǎng)技術(shù)結(jié)合,創(chuàng)造個(gè)性化、用戶體驗(yàn)好的作品,建站類型包括:網(wǎng)站制作、做網(wǎng)站、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣、域名與空間、網(wǎng)絡(luò)空間、企業(yè)郵箱。業(yè)務(wù)覆蓋同心地區(qū)。
String?reg?=?"name\\s*\\=\\s*[\\w\'\"[^\\]]+|value\\s*\\=\\s*[\\w\'\"\\s[^\\]]+";
Pattern?pattern?=?Pattern.compile?(reg);
Matcher?matcher?=?pattern.matcher?(temp);
while?(matcher.find?())
{
System.out.println?(matcher.group?());
}
用Java模擬form表單提交的方法,在struts2中的配置如下:
!-- action屬性為actionNmae!methodName的形式
其中ActionName指定提交到哪個(gè)Action,而methodName指定提交到指定方法--
action="ActionName!add"
其中一個(gè)按鈕的代碼如下:
input type="submit" value="注冊" onclick="regist();" /
點(diǎn)擊“注冊”按鈕被單擊時(shí)觸發(fā)regist函數(shù),該函數(shù)的代碼如下:
script type="text/javascript"
function regist(){
targetForm = document.forms[0];
targetForm.action = "login!add";
}
/script
java中使用request.getParameter("參數(shù)名")方法來獲取form表單傳過來的數(shù)據(jù)。
具體代碼如下:
jsp代碼:
%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%
!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
html
head
titleDemo/title
meta http-equiv="pragma" content="no-cache"
meta http-equiv="cache-control" content="no-cache"
meta http-equiv="expires" content="0"
meta http-equiv="keywords" content="keyword1,keyword2,keyword3"
meta http-equiv="description" content="This is my page"
/head
body
form action="demoServlet" method="post"
table
tr
td
input type="text" name="name" id="name"/
/td
/tr
tr
td
input type="submit" value="提交"/
/td
/tr
/table
/form
/body
/html
Servlet代碼:
public class DemoServlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String name = request.getParameter("name");
System.out.println(name);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
}
}
其中DemoServlet是一個(gè)繼承了HttpServlet類的Servlet類,當(dāng)表單提交(點(diǎn)擊提交按鈕)時(shí),回去調(diào)用這個(gè)類的doPost()方法,執(zhí)行對應(yīng)的代碼,通過request.getParameter("name")來獲取表單的值。
前臺(tái)頁面form表單 action="LoginServlet" method="post"
后臺(tái)頁面 Servlet 調(diào)用doPost方法 執(zhí)行代碼,
使用request.getParameter("參數(shù)名")方法來獲取form表單傳過來的數(shù)據(jù)
import?java.util.*;
import?java.util.regex.*;
class?Tester{
private?static?String?get(String?input,?String?tagName,?String?key){
String?reg?=?"(?i)"?+?tagName?+?"[^]*("?+?key?+?")[=\"\'\\s]+([^\"\']*)[\"\']?";
Pattern?p?=?Pattern.compile(reg);
Matcher?m?=?p.matcher(input);
String?result?=?"";
while(m.find()){
result?+=?m.group(2)?+?"|";
}
return?result.replaceAll("\\|$","");
}
public?static?void?main(String[]?args){
String?input?=
"form?name='form1'?method='post'?action=''input?type='hidden'?name='Retdesc'?value='parameters?error'input?type='hidden'?name='user'?value='333'/formscriptdocument.form1.submit();/script";
HashMapString,?String?map?=?new?HashMapString,?String();
map.put("action",?get(input,?"form",?"action"));
map.put("name",?get(input,?"input",?"name"));
map.put("value",?get(input,?"input",?"value"));
System.out.println(map);
}
}
submit屬于提交按鈕,談不上調(diào)用java代碼吧,只是通過html標(biāo)簽里的功能實(shí)現(xiàn)提交表單。