学习jsp视频20(MVC模式与servlet执行流程(初见))心得总结

本文详细介绍了MVC架构在Web开发中的应用,包括model、view、controller各层的作用及其实现方式。通过一个具体的例子,展示了如何使用Servlet作为控制器,处理从前端页面接收的数据,并调用相应的业务逻辑。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

mvc module模型层,view视图层,control层。其中,视图层就是前端技术编写的页面,module层是对前端页面传过来的数据进行处理,是一个有java语言编写的类,而control层则是控制view与module一一对应的结构,什么数据该发给什么modul

servlet执行流程

1,先自己在web-content文件夹下面编写一个welcome.jsp文件(类似于view层)

<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
<title>Insert title here</title>
</head>
<body>
	<a href="welcomeservlet">welcomeservlet</a>
	<form action="welcomeservlet" method="post">
		<input type="submit" value="提交请求">
	
	</form>
</body>
</html>

2然后在src文件夹下面创建一个welcomeservlet.java文件(类似于module层)`

package org.lanqiao.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class welcomeservlet extends HttpServlet{
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		System.out.println("doget...");
		
	}
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		System.out.println("dopost...");
	}
}

3 在web.xml中添加相关语句(实现control层功能,将执行的代码和javabean一一对应)

?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>Servlet25project</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
  
  <servlet>
  <servlet-name>welcomeservlet</servlet-name>
  <servlet-class>org.lanqiao.servlet.welcomeservlet</servlet-class>
  </servlet>
  
  <servlet-mapping>
  		<servlet-name>welcomeservlet</servlet-name>
  		<url-pattern>/welcomeservlet</url-pattern>
  </servlet-mapping>
</web-app>

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值