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>
