jsp如何获得html form中的数据

html-css012

jsp如何获得html form中的数据,第1张

HTML:

<form action="a.jsp">

<input type="text" name="test_data"/>

<input type="submit" value="提交" />

</form>

a.jsp:

<%

String testData = request.getParameter("test_data")   // 即可获得test_data的值。

%>

扩展资料:

页面间链接和数据传递的三种方式

(1)通过JSP表单形式将数据提交到下一个页面

(2)通过JSP表单链接将数据提交到下一个页面

(3)通过JSP表单会话将数据提交到后续页面,会话是一次会话只要浏览器不关闭就不会关闭会话,一般默认保存30分钟可以根据自己的需要更改。

首先:这样写:

out.println(request.getParameter("username")

)

是可以实现的,如果要输出中文还必须写个处理中文的函数

<%!public

String

codeToString(String

str)

{

String

s=str

try{

byte

tempB[]=s.getBytes("ISO-8859-1")

s=new

String(tempB)

return

s

}

catch(Exception

e)

{

return

s

}

}

%>

然后输出的话

调用这个函数:codeToString(request.getParameter("username"))

当然也可以把上面这句加入到out.println()里面

还要主意的是:request.getParameter("username")

里面的

用的是双引号,不是单引号