弱弱问个问题,如何request.getParameter("username")能获取到123456789,不刷新页面,自动提交获取。觉得不可能,但是...源码如下:<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>test</title>
</head>
<body>
<form name="form1" id="form1" action="why.jsp" method="post">
<input type="text" name="username" id="username" value="123456789"/>
<input type="submit" name="sbt" id="sbt" value="test"/>
</form>
<%="userName::::"+request.getParameter("username") %>
</body>
</html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>test</title>
</head>
<body>
<form name="form1" id="form1" action="why.jsp" method="post">
<input type="text" name="username" id="username" value="123456789"/>
<input type="submit" name="sbt" id="sbt" value="test"/>
</form>
<%="userName::::"+request.getParameter("username") %>
</body>
</html>
然后request.getParameter(result)
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.regex.Matcher;
import java.util.regex.Pattern;public class TestCutString {
public static void main(String[] args) {
String url = "http://product.dangdang.com/product.aspx?product_id=20689512";
//你可以替换你的url
String content = getURLContent(url, "gb2312");
String regStr = "<h1>(.*?)</h1>";// 你可以替换正则表达式
//替换为:regStr = "<input type=\"text\" name=\"username\" id=\"username\" value=\"(.*)\"/>";
Pattern pattern = Pattern.compile(regStr);
Matcher matcher = pattern.matcher(content);
String result = null;
if (matcher.find())
result = matcher.group(1);
System.out.println(result);
} public static String getURLContent(String urlString, String encoding) {
if (urlString == null || "".equals(urlString.trim()))
return null; StringBuffer content = new StringBuffer();
try {
// 新建URL对象
URL url = new URL(urlString);
InputStream in = new BufferedInputStream(url.openStream());
InputStreamReader theHTML = new InputStreamReader(in,
encoding != null ? encoding : "gb2312");
int c;
while ((c = theHTML.read()) != -1) {
content.append((char) c);
}
}
// 处理异常
catch (MalformedURLException e) {
System.err.println(e);
} catch (IOException e) {
System.err.println(e);
}
return content.toString();
}}