JSP的内置对象

request常用方法的使用,编写获取表单数据。

Register.jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>

<%

String path = request.getContextPath();

String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

%>

<%@ page contentType="textml; charset=gb2312" %>

<script languge="java">

function submit(){

if(form1.username.value==""){

alert("用户名不能为空,请输入用户名!");

form1.username.focus();

return false;

}

if(form1.userpassword.value==""){

alert("用户密码不能为空,请输入密码!");

form1.userpassword.focus();

return false;

}

if(form1.userpassword.value!=form1.resuerpassword.value){

alert("密码与确认密码不同");

form1.userpassword.focus();

return false;

}

if(form1.email.value.length!=0){

for(i=0;i<forml.email.value.length;i++)

if(forml.email.value.charAt(i)=="@")

break;

if(i==forml.email.value.length)

{

alert("非法EMail地址!");

forml.email.focus();

return false;

}

}

else

{

alert("请输入Email!");

forml.email.focus();

return false;

}

}

</script>

<html>

 

  <head>

  </head>

  

  <body>

    <form  method="POST"  name="form1" οnsubmit="submit()">

    新用户注册<br>

    用户名(*):<input type="text" name="username" size="20"><br>

    密 码:<input type="password" name="userpassword" size="20"><br>

    性别:<input type="radio" value="男" name="sex">男<input type="radio" name="sex" value="女">女<br>

    出生年月:<input name="year" size="4" maxlength=4>年

    <select name="month">

    <option value="1" selected>1</option>

    <option value="2" selected>2</option>

    <option value="3" selected>3</option>

    <option value="4" selected>4</option>

    <option value="5">5</option>

    <option value="6">6</option>

    <option value="8">7</option>

    <option value="9">9</option>

    <option value="10">10</option>

    <option value="11">11</option>

    <option value="12">12</option>

    <lect>月

    <input name="day" size="3" maxlength=4>日<br>

    电子邮箱(*):<input name="email" maxlength=28><br>

    家庭住址:<input type="text" name="address" size="20"><br>

    <input type="submit" value="提交" name="B1"><input type="reset" value="全部重写" name="B2"><br>

    </form>

  </body>

</html>

 

Accept.jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>

<%

String path = request.getContextPath();

String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

%>

 

<%@page contentType="text/html; charset=gb2312" %>

<%!

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;

}

}

 %>

<html>

  <head>

    <base href="<%=basePath%>">

    

    <title>接受新用户注册</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">

<!--

<link rel="stylesheet" type="text/css" href="styles.css">

-->

  </head>

  <body>

    用户名是:<%=codeToString(request.getParameter("username")) %><br>

    密码是:<%=codeToString(request.getParameter("userpassword")) %><br>

    性别是:<%=codeToString(request.getParameter("sex")) %><br>

    出生年月是:<%=request.getParameter("year")+request.getParameter("month")+request.getParameter("day") %><br>

    电子邮箱是:<%=request.getParameter("email") %><br>

    家庭住址是:<%=codeToString(request.getParameter("address")) %><br>

  </body>

</html>

截图:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值