JSP表单
[input name="password" type="password"/> [input type="submit" value="提交"/>
重置表单: [input name="reset" type="reset" />
重置表单(超链接): [a href='JavaScript:myform.reset();'>重置
提交表单: [input name="submit" type="submit" />
提交表单(图片代替按钮): [input name="image" type="image" src="image/sumbit.gif" />
提交表单(超链接):[a href='JavaScript:myform.submit();'>提交
字符串: [input type="text" name="ZiFuChuan" value="MoRenZhi" />
密码:[input type="password" name="MiMa" value="MoRenZhi">
一段文字:[textarea name="YiDuanWenZi" rows="2" Cols="3">1234
输入文件:[input type="file" name="upload" /> 在[head>上面添加负责客户端验证的JavaScript [script> function checklength(){ if(document.myform.username.value.length<3||document.myform.username.value.length>10){ alert("哎呀,名称错了,老师怎么教的?");return false; } if(document.myform.password.value.length==""||(document.myform.password.value.length<6||document.myform.password.value.length>10)){ alert("妈的,密码错了!回家问家长去!");return false;} return true; } [/script> 其中超链接提交和重置没有成功。 填写提交后 This Is Submitted By A Form upload: YiDuanWenZi:1234 password:123123 ZiFuChuan:MoRenZhi MiMa:MoRenZhi username:12312 ------------------------------------------------------------------------------------------------------------------------------------------------------- 选择信息类表单
下拉菜单:
[form name="form" method="post" action="getform.jsp"> [select name="peoples"> [option value="A" selected="selected">Aa [option value="B" >Bb [option value="C" >Cc [/select> [input type="submit" value="Go"> [/form>单选按钮(可以分为多组):
[form name="form1" method="post" action="getform.jsp"> [input type="radio" name="q" value="Qq1"/> q1[input type="radio" name="q" value="Qq2" /> q2
[input type="radio" name="w" value="Qq3" /> q3
[input type="submit" value="Goooooooooooooo" /> [/form> 复选按钮: [form name="form2" method="post" action="getform.jsp"> [input type="checkbox" name="sports" value="swimming" />游泳
[input type="checkbox" name="sports" value="running" />跑步
[input type="checkbox" name="sports" value="skating" />滑冰
[input type="checkbox" name="sport" value="climp"/>攀岩
[input type="checkbox" name="sport" value="dive"/>潜水
[input type="checkbox" name="sport" value="skim"/>滑雪
[input type="submit" value="Dooooooooooooooooooooo"> [/form> 隐藏信息: [form name="form3" method="get" action="getform.jsp"> [ input type="hidden" name="WomanAge" value="secret" /> [input type="submit" value=" Askkkkkkkkkkkkkkkkkkkkk"/> [/form> 测试botton: [form name="form4" method="get" action="getform.jsp"> [input type="text"> [input type="botton" value="value" name="name" /> [/form>
This Is Submitted By A Form
<% //得到所有参数名称 java.util.Enumeration e=request.getParameterNames(); //对所有参数进行循环 while(e.hasMoreElements()) { //得到参数名 String name = (String)e.nextElement(); //得到这个参数所有值 String [] value=request.getParameterValues(name); //打印参数名 out.print(name+":"); //对一个参数的所有值进行循环 for(int i=0;i"); } %> getInfo.jsp <%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
Information about the request
Query String:::::::<%=request.getQueryString()%><%--得到参数字符串--%> Request URL:::::::<%=request.getRequestURI()%>
<%--得到要求访问的页面--%> JSP Path:::::::<%=request.getServletPath()%>
<%--得到JSP页面实际存放的位置--%> Protocol:::::::<%=request.getProtocol()%>
<%--得到使用的传输协议--%> Browser:::::::<%=request.getHeader("User-Agent")%>
<%--得到客户端浏览器类型--%> Client Address::::::<%=request.getRemoteAddr()%>
<%=request.getRemoteHost()%>
<%=request.getRemoteUser()%>
<%--得到客户端地址、主机名、、--%> Scheme:<%=request.getScheme()%>
<%--得到访问策略--%> ServerName:::::::<%=request.getServerName()%>
8080:::: <%=request.getServerPort()%>
/getInfo.jsp:::: <%=request.getServletPath()%>
<%--得到本地主机名、端口号、路径--%> getAuthType()::::<%=request.getAuthType()%>
<%----%> getCharacterEncoding():::<%=request.getCharacterEncoding()%>
<%--得到字符集--%> getContentLength():::<%=request.getContentLength()%>
null:::<%=request.getContentType()%>
getAttributeNames()::::<%=request.getAttributeNames()%>
getContextPath():::<%=request.getContextPath()%>
getCookies():::<%=request.getCookies()%>
getHeaderNames():::<%=request.getHeaderNames()%>
getInputStream():::<%=request.getInputStream()%>
getLocale()::::<%=request.getLocale()%>
getLocales():::::::<%=request.getLocales()%>
getMethod()::::::<%=request.getMethod()%>
getParameterNames()::::::<%=request.getParameterNames()%>
getPathTranslated():::::<%=request.getPathTranslated()%>
getRequestedSessionId(:::::<%=request.getRequestedSessionId()%>
isSecure():::::<%=request.isSecure()%>
isRequestedSessionIdValid()::::<%=request.isRequestedSessionIdValid()%>
isRequestedSessionIdFromURL()::::<%=request.isRequestedSessionIdFromURL()%>
request.isRequestedSessionIdFromCookie()::::<%=request.isRequestedSessionIdFromCookie()%>
request.getUserPrincipal():::<%=request.getUserPrincipal()%> 我执行的结果:
密码:[input type="password" name="password" value="123456" />
[input type="submit" value="提交" /> [/form> [/body> [/html>
用户名:<%=request.getParameter("username")%>
密码:<%=request.getParameter("password")%>
img alt="5.GIF" src="http://www.trucy.org/blog/pinkfloyd/archives/5.GIF" width="1024" height="768" /> 引用Java类。以下是显示现在时间。Time.jsp <%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %> <%@ page import = "java.util.*"%> 现在时间: <%Calendar cal = Calendar.getInstance();%> <%out.print(cal.get(Calendar.YEAR));%>年 <%out.print(cal.get(Calendar.MONTH));%>月 <%out.print(cal.get(Calendar.DATE));%>日 <%out.print(cal.get(Calendar.HOUR));%>时 <%out.print(cal.get(Calendar.MINUTE));%>分 <%out.print(cal.get(Calendar.SECOND));%>秒