当前位置:网站首页>Servlet student management system (Mengxin hands-on version)
Servlet student management system (Mengxin hands-on version)
2022-06-29 18:09:00 【Soup key TJ】
Catalog
Introduce
Implementation steps
- 1. Create a web project
- 2. Create a... To save student information HTML file
- 3. Create a class , Inherit HttpServlet
- 4. rewrite doGet and doPost Method
- 5. stay web.xml File to modify the default home page and configuration Servlet( To modify the default home page is to configure the default home page to the one just created HTML file )
- 6. stay doGet Method to save the form data to a file , And respond to the browser results
- 7. Deploy and launch the project
- 8. Pass the browser test
Concrete realization
- action Location : Virtual path + Resource access path
- stay HttpServletRequest in
- request.getParameter() Method
- adopt name Get the corresponding value for the property name of
- 1. Get through http Data submitted by agreement . Through the implementation of the container get perhaps post Data submitted by
- 2.request.getParameter() Method passed data , From web Client to web Server side , representative HTTP Request data , This method returns String Data of type
- HTML The file is kept in web In the catalog
package com.example.servletdemo1; import java.io.*; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class HelloServlet extends HttpServlet { protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // Get form data String username = request.getParameter("username"); String age = request.getParameter("age"); String score = request.getParameter("score"); // Use character output stream BufferedWriter bw = new BufferedWriter(new FileWriter("D:\\test\\my\\tj.txt",true)); bw.write(username+","+age+","+score); bw.newLine(); bw.close(); // Respond to client browser PrintWriter pw = response.getWriter(); pw.println("Save Success"); pw.close(); } protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doGet(request,response); } }
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd" version="4.0"> <!-- Modify the default home page --> <welcome-file-list> <welcome-file>/addStudent.html</welcome-file> </welcome-file-list> <!-- To configure Servlet --> <servlet> <servlet-name>studentServlet</servlet-name> <servlet-class>com.example.servletdemo1.HelloServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>studentServlet</servlet-name> <url-pattern>/cpc</url-pattern> </servlet-mapping> </web-app>
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title> Save student information </title> </head> <body> <form action="/demo2/cpc" method="get" autocomplete="off"> The student's name :<input type="text" name="username"> <br/> Student age :<input type="number" name="age"> <br/> Student achievement :<input type="number" name="score"> <br/> <button type="submit"> preservation </button> </form> </body> </html>
- The effect is as shown in the picture :
- Click save
边栏推荐
- Does rapid software delivery really need to be at the cost of security?
- Function independent watchdog (iwdg) experiment based on stm32f103zet6 Library
- 两种Controller层接口鉴权方式
- Serial port experiment based on stm32f103zet6 library function
- /usr/bin/ld: warning: **libmysqlclient.so.20**, needed by //usr/
- [webdriver] upload files using AutoIT
- VB.Net读写NFC Ntag标签源码
- How QQ opens online customer service
- 图像特征计算与表示——基于内容的图像检索
- 3H proficient in opencv (VII) - color detection
猜你喜欢
NVIDIA installs the latest graphics card driver
Kubekey2.2.1 kubernetes1.23.7 offline package production +harbor Department summer and upload image
Analyze the implementation principle of zero copy mechanism, applicable scenarios and code implementation
Distributed | several steps of rapid read / write separation
Adobe Premiere基础-编辑素材文件常规操作(脱机文件,替换素材,素材标签和编组,素材启用,便捷调节不透明度,项目打包)(十七)
VB. Net read / write NFC ntag tag source code
Matlab farthest point sampling (FPS)
让 Google 搜索到自己的博客
Request header field xxxx is not allowed by Access-Control-Allow-Headers in preflight response问题
Spingmvc requests and responses
随机推荐
[tcapulusdb knowledge base] tcapulusdb system user group introduction
工作流模块Jar包启动报错:liquibase – Waiting for changelog lock….
Wechat applet development reserve knowledge
mac安装php7.2
Detailed introduction and Simulation of bitmap
Xiaomai technology x hologres: high availability of real-time data warehouse construction of ten billion level advertising
Createstore for Redux source code analysis
Sword finger offer 13 Robot range of motion (BFS)
小程序容器是什么技术?能助力物联网企业红海突围?
通过 hosts文件配置本地域名
Teach you how to install the latest version of mysql8.0 database on windows, nanny level teaching
测试dble split功能执行+导入耗时shell脚本参考
mongoTemplate - distinct 使用
Test dble split function execution + import time-consuming shell script reference
Goldfish rhca memoirs: do447 build advanced job workflow -- create job template survey to set work variables
3H proficient in opencv (V) - perspective transformation
SSH protocol learning notes
Matlab farthest point sampling (FPS)
Have you grasped the most frequently asked question in the interview about massive data processing?
Adobe Premiere基础-常用的视频特效(边角定位,马赛克,模糊,锐化,手写工具,效果控件层级顺序)(十六)