当前位置:网站首页>Programming technology of Servlet
Programming technology of Servlet
2022-07-21 23:38:00 【Crazy beauty is stupid】
One 、 The experiment purpose
understand Servlet How it works , master Servlet Application development method of ; Master common Servlet ;
Two 、 The experimental requirements
- understand Servlet Application .
- master Servlet The programming technology of the .
- Skillfully use Eclipse Development Servlet application
3、 ... and 、 Experimental content
( One ) use Servlet Get form data
- Build a Servlet file accept.java And a register.jsp file , To achieve Servlet Realize the function of obtaining form data .
- Program function : utilize Servlet To achieve the acquisition of form data .
- Reference source code :
accept.java
import java.io.*; import javax.servlet.*;
import javax.servlet.http.*;
public class acceptUserRegist extends HttpServlet
{
public String codeToString(String str)
{// Functions for processing Chinese strings String s=str;
try
{
byte tempB[]=s.getBytes("ISO-8859-1"); s=new String(tempB);
return s;
}
catch(Exception e)
{
return s;
}
}
public void init(ServletConfig config) throws ServletException
{
super.init(config);
}
response)
public void doPost(HttpServletRequest request,HttpServletResponse
throws ServletException,IOException
{
// set up Set up mime response.setContentType("text/html;charset=GB2312"); PrintWriter out=response.getWriter();
out.println("<HTML><head><title> Receive new user registration
</title></head><BODY>");
out.println(" This is the data submitted by the new user registration :<br>");
out.println(" use Household name yes : "+codeToString(request.getParameter("username"))+"<br>");
out.println(" The secret code yes : "+codeToString(request.getParameter("userpassword"))+"<br>");
out.println(" sex other yes : "+codeToString(request.getParameter("sex"))+"<br>");
out.println(" Out raw year month yes : "+request.getParameter("year")+request.getParameter("month")+request.getParamet er("day")+"<br>");
out.println(" The email address is :"+request.getParameter("email")+"<br>");
out.println(" home Court live site yes : "+codeToString(request.getParameter("address"))+"<br>");
out.println("</body> </html>");
}
}
register.jsp
<%@ page contentType="text/html;charset=gb2312"%>
<script language="javascript"> function on_submit()
{// Verify the validity of the data
if (form1.username.value == "")
{
alert(" The username cannot be empty , Please enter a user name !"); form1.username.focus();
return false;
}
if (form1.userpassword.value == "")
{
alert(" User password cannot be empty , Please input a password !"); form1.userpassword.focus();
return false;
}
if (form1.reuserpassword.value == "")
{
alert(" The user confirmation password cannot be empty , Please input a password !"); form1.reuserpassword.focus();
return false;
}
if (form1.userpassword.value != form1.reuserpassword.value)
{
alert(" The password is different from the confirmation password "); form1.userpassword.focus(); return false;
}
if (form1.email.value.length!= 0)
{
for (i=0; i<form1.email.value.length; i++) if (form1.email.value.charAt(i)=="@")
break;
if (i==form1.email.value.length)
{
else
{
alert(" illegal EMail Address !"); form1.email.focus(); return false;
}
}
alert(" Please enter Email!"); form1.email.focus(); return false;
}
}
</script>
<html>
<head>
<title> New user registration </title>
</head>
<body>
<form method="POST" action="servlet/accept" name="form1" οnsubmit="return on_submit()">
New user registration <br>
user name (*):<input type="text" name="username" size="20"><br>
The secret ; code (*):<input type="password" name="userpassword" size="20"><br> Enter the password again (*):<input type="password" name="reuserpassword" size="20"><br> Gender :<input type="radio" value=" male " checked name="sex"> male <input type="radio"
name="sex" value=" Woman "> Woman <br>
date of birth :<input name="year" size="4" maxlength=4> year
<select name="month">
<option value="1" selected>1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">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>
</select> month
<input name="day" size="3" maxlength=4> Japan <br>
email (*):<input name="email" maxlength=28><br>
Home address :<input type="text" name="address" size="20"><br>
<input type="submit" value=" Submit " name="B1"><input type="reset" value=" Rewrite all " name="B2"><br>
</form>
</body>
</html>
- Compile and run the program .
边栏推荐
- [first acquaintance with JMeter and thread group]
- 软件测试面试题与答案【一】
- 文件下载,用例怎么写?
- "JMeter uses the XPath extractor to obtain the value value in the request response as the input of the next request" case
- 如何做冒烟测试
- 团队人员英文简称
- 实现页面与页面之间的信息交换
- Audio and video development learning notes (I)
- How do you understand automated testing? Understand the purpose and essence of automated testing
- sysstat安装并升级到11.5.5版本
猜你喜欢
How to evaluate the test quality?
JMeter之响应断言
004_ SSSS_ Image-to-Image Translation with Conditional Adversarial Networks
“cannot get hvm parameter CONSOLE_EVTCHN (18): -22!” Solution of
[advanced semiconductor process technology series] SOI Technology (middle)
连接以前可用的MySQL数据库报10061 unknown error 错误
2021-06-22
loadrunner清除浏览器缓存
sysstat安装并升级到11.5.5版本
你是怎么理解自动化测试的?理解自动化测试的目的和本质
随机推荐
28岁想入行软件测试,可行吗?
棋盘覆盖问题
整数变换问题
Day01 software testing foundation summary
如何评价测试质量?
Test case exercise 2 - vendor account information
004_ SSSS_ Image-to-Image Translation with Conditional Adversarial Networks
Extract a number from a string
[semiconductor advanced process technology series] HKMG process technology (Part 2)
对于依赖第三方的接口如何进行测试?
动态规划求解(添+号求最小值和问题)
No idea about interface testing? An article to teach you how to handle the interview
接口测试(1)
[first acquaintance with JMeter and thread group]
Payment system test
Day03 test case knowledge points summary (Part 2)
postman的body中报“Expected ‘,‘instead of ‘p‘”的解决方法
APP 注册功能,用例怎么写 ?
APP 登录功能,用例怎么写 ?
Exploratory software testing