- 从inputtext.jsp跳转到inputtext1res.jsp,同时将输入框的值送post的方式传递过去
- 定义输入框的默认值以及点击事件
- 在inputtext1res.jsp当中使用request.getParameter(”输入框的name”)即可获取到数值 ,如果要获取同一name的多个值可以使用reques.getParameterValues(“输入框的name”)
- input的其他类型,比如radio,textarea等都差不多,
inputtext1.jsp:
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<style>
.black {
color:#000;
}
.grey {
color:#b3b3b3;
}
</style>
</head>
<body>
<!-- 使用post的方法,点击后跳转到inputtext1res.jsp -->
<form action="inputtext1res.jsp" method="post">
用户名:
<!-- 设置onclick事件,默认为Hello,点击输入框自动消失,另外设置onblur事件,如果焦点不在输入框这重新显示默认值 -->
<input type="text" name="UserName" value="Hello" onclick="if(this.value=='Hello'){
this.value='';this.className='balck'
}" onblur="if(this.value==''){
this.value='Hello';this.className='grey'
}"
/>
<br />
<!-- type设置为submit,直接提交 -->
<input type="submit" name="submit1" value="提交">
</form>
</body>
</html>
inputtext1res.jsp:
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<!-- 获取到inputtext1.jsp传过来的值并输出,其中UserName即为输入框的名字 -->
<%=request.getParameter("UserName") %>
</body>
</html>
效果截图: