1. 程式人生 > 資訊 >美國 FBI 系統被入侵,黑客向 10 萬郵箱傳送假冒郵件

美國 FBI 系統被入侵,黑客向 10 萬郵箱傳送假冒郵件

Spring MVC 是 Spring 提供的一個基於 MVC 設計模式的輕量級 Web 開發框架,本質上相當於 Servlet。

需要的jar

web.xml配置SpringMVC

<?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_3_0.xsd"
id="WebApp_ID" version="3.0"> <display-name>spring_mvc_lx01</display-name> <!-- SpringMVC核心配置檔案 --> <servlet> <servlet-name>springmvc</servlet-name> <!-- SpringMVC的實現 --> <servlet-class>org.springframework.web.servlet.DispatcherServlet</
servlet-class> <!--Spring MVC 初始化時將在應用程式的 WEB-INF 目錄下查詢配置檔案,該配置檔案的命名規則是“servletName-servlet.xml”--> <!--servletName就是web.xml裡對應的servlet-name--> <!--例如 springmvc-servlet.xml。 否則執行以下--> <!-- 載入SpringMVC其他的配置檔案 --> <init-param> <
param-name>contextConfigLocation</param-name> <param-value>classpath:Spring-MVC.xml</param-value> </init-param> <!-- 優先順序 --> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>springmvc</servlet-name> <!-- 需要處理的請求 --> <url-pattern>*.do</url-pattern> </servlet-mapping> </web-app>

SpringMVC主配置檔案

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
        http://www.springframework.org/schema/beans/spring-beans-3.2.xsd 
        http://www.springframework.org/schema/mvc 
        http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd 
        http://www.springframework.org/schema/context 
        http://www.springframework.org/schema/context/spring-context-3.2.xsd 
        http://www.springframework.org/schema/aop 
        http://www.springframework.org/schema/aop/spring-aop-3.2.xsd 
        http://www.springframework.org/schema/tx 
        http://www.springframework.org/schema/tx/spring-tx-3.2.xsd ">
        
        <!-- 開啟註解配置 -->
        <context:annotation-config/>
        <!-- 掃描指定controller的包(構造掃描) -->
        <context:component-scan base-package="Controller"/>
        <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
            <!-- 配置jsp路徑的字首 -->
            <property name="prefix" value="jsp/"/>
            <!-- 配置jsp路徑的字尾 -->
            <property name="suffix" value=".jsp"/>
        </bean>
    
</beans>

javabean(entity)

Controller

package Controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import entity.User;
@Controller
public class User_controller {
    @RequestMapping("login.do")
    public String login(User user) {
        System.out.println(user.getUsername()+user.getPassword());
        return "redirect:add.do";
    }
    @RequestMapping("add.do")
    public String add(User user) {
        
        return "success";
    }
}

jsp頁面

面試題:SpringMVC執行流程

人生永遠無法回頭,就連這平淡不驚的一幕,終有一日也會碎落滿地