当前位置:网站首页>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


边栏推荐
- Image feature computation and representation -- content based image retrieval
- 双亲委派机制
- Bloom filter:
- Adobe Premiere基础-常用的视频特效(裁剪,黑白,剪辑速度,镜像,镜头光晕)(十五)
- 给定一个数在序列中求最大异或值(01字典)
- EasyCVR部署服务器集群时,出现一台在线一台不在线是什么原因?
- Adobe Premiere基础-编辑素材文件常规操作(脱机文件,替换素材,素材标签和编组,素材启用,便捷调节不透明度,项目打包)(十七)
- 【目标跟踪】|stark配置 win otb
- On adding and subtracting dates
- NVIDIA installs the latest graphics card driver
猜你喜欢

Niuke small Bai monthly race 52 D ring insectivorous (feet +st table)

Proxmox VE Install 7.2

国内酒店交易DDD应用与实践——理论篇

小程序容器是什么技术?能助力物联网企业红海突围?

Adobe Premiere基础-编辑素材文件常规操作(脱机文件,替换素材,素材标签和编组,素材启用,便捷调节不透明度,项目打包)(十七)

The soft youth under the blessing of devcloud makes education "smart" in the cloud

Premature end of script headers 或 End of script output before headers

Prevent form resubmission based on annotations and interceptors

Adobe Premiere基础-批量素材导入序列-变速和倒放(回忆)-连续动作镜头切换-字幕要求(十三)

Visio annotation, annotation location
随机推荐
Teach you how to install the latest version of mysql8.0 database on windows, nanny level teaching
Spingmvc requests and responses
Image migration and data migration synchronization of old and new servers with different Alibaba cloud accounts
3H proficient in opencv (VI) - image stacking
Precondition end of script headers or end of script output before headers
[网鼎杯 2020 青龙组]AreUSerialz
Proxmox VE Install 7.2
小程序容器是什么技术?能助力物联网企业红海突围?
[target tracking] |stark configuration win OTB
Premature end of script headers 或 End of script output before headers
What technology is an applet container? Can it help Internet of things enterprises break through the red sea?
Mysql database daily backup and scheduled cleanup script
Maximum length of palindrome substring (string hash + binary)
Yurun multidimensional makes efforts in the charity field and bravely resists the corporate public welfare banner
Partial mock of static class of phpunit operation
Image feature computation and representation -- content based image retrieval
图像特征计算与表示——基于内容的图像检索
回文子串的最大长度(字符串哈希+二分)
You can do sideline work
软件快速交付真的需要以安全为代价吗?







