1. 程式人生 > 其它 >IOS – OpenGL ES 調節影象單色 GPUImageMonochromeFilter

IOS – OpenGL ES 調節影象單色 GPUImageMonochromeFilter

一、建立工程

1、建立一個maven工程

2、右鍵工程目錄,新增web4.0框架支援

3、最終檔案目錄結構

二、編寫配置檔案

1、pom.xml

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <project xmlns="http://maven.apache.org/POM/4.0.0"
 3          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 4          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
 5
<parent> 6 <artifactId>SpringMVC-KS</artifactId> 7 <groupId>org.example</groupId> 8 <version>1.0-SNAPSHOT</version> 9 </parent> 10 <modelVersion>4.0.0</modelVersion> 11 12 <artifactId>springmvc-03-annotion</artifactId> 13
14 <!-- 依賴 --> 15 <dependencies> 16 <dependency> 17 <groupId>junit</groupId> 18 <artifactId>junit</artifactId> 19 <version>4.12</version> 20 </dependency> 21 <!--spring-webmvc依賴--> 22
<dependency> 23 <groupId>org.springframework</groupId> 24 <artifactId>spring-webmvc</artifactId> 25 <version>5.2.13.RELEASE</version> 26 </dependency> 27 <!--springmvc底層還是servlet,所以必須新增serlvet依賴--> 28 <dependency> 29 <groupId>javax.servlet</groupId> 30 <artifactId>javax.servlet-api</artifactId> 31 <version>4.0.1</version> 32 <!-- 作用在打包時確保servlet不會打包進去 --> 33 <scope>provided</scope><!--因為tomcat外掛的有提供servlet,所以如果打包進去外掛就會啟動會失敗--> 34 </dependency> 35 <dependency> 36 <groupId>javax.servlet.jsp</groupId> 37 <artifactId>jsp-api</artifactId> 38 <version>2.2</version> 39 </dependency> 40 <dependency> 41 <groupId>javax.servlet</groupId> 42 <artifactId>jstl</artifactId> 43 <version>1.2</version> 44 </dependency> 45 </dependencies> 46 47 <build> 48 <resources> 49 <resource> 50 <directory>src/main/java</directory> 51 <includes> 52 <include>**/*.properties</include> 53 <include>**/*.xml</include> 54 </includes> 55 <filtering>false</filtering> 56 </resource> 57 <resource> 58 <directory>src/main/resources</directory> 59 <includes> 60 <include>**/*.properties</include> 61 <include>**/*.xml</include> 62 </includes> 63 <filtering>false</filtering> 64 </resource> 65 </resources> 66 </build> 67 </project>

2、web.xml

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
 3          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 4          xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
 5          version="4.0">
 6 
 7 <servlet>
 8     <servlet-name>SpringMVC</servlet-name>
 9     <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
10     <init-param>
11         <param-name>contextConfigLocation</param-name>
12         <!--注意classpath後文件名根據歷史約定,一般為servlet-name+-servlet這種命名方式-->
13         <param-value>classpath:SpringMVC-servlet.xml</param-value>
14     </init-param>
15     <load-on-startup>1</load-on-startup>
16 </servlet>
17 
18 <servlet-mapping>
19     <servlet-name>SpringMVC</servlet-name>
20     <url-pattern>/</url-pattern>
21 </servlet-mapping>
22 
23 <!--    自己手寫一個過濾器-->
24 <!--    <filter>-->
25 <!--        <filter-name>encoding</filter-name>-->
26 <!--        <filter-class>com.han.filter.EncodingFilter</filter-class>-->
27 <!--    </filter>-->
28 <!--    <filter-mapping>-->
29 <!--        <filter-name>encoding</filter-name>-->
30 <!--        <url-pattern>/*</url-pattern>-->
31 <!--    </filter-mapping>-->
32 
33 <!--    springmvc自帶的過濾器-->
34 <filter>
35     <filter-name>encoding</filter-name>
36     <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
37     <init-param>
38         <param-name>encoding</param-name>
39         <param-value>utf-8</param-value>
40     </init-param>
41 </filter>
42 <filter-mapping>
43     <filter-name>encoding</filter-name>
44     <url-pattern>/*</url-pattern> <!-- 這裡如果時/,就會把jsp檔案過濾掉-->
45 </filter-mapping>
46 </web-app>

3、編寫SpringMVC-servlet.xml

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <beans xmlns="http://www.springframework.org/schema/beans"
 3        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 4        xmlns:context="http://www.springframework.org/schema/context"
 5        xmlns:mvc="http://www.springframework.org/schema/mvc"
 6        xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc https://www.springframework.org/schema/mvc/spring-mvc.xsd">
 7     
 8     <!-- 掃描controller下的元件 -->
 9     <context:component-scan base-package="com.han.controller"/>
10     <!-- spring mvc不處理靜態資源-->
11     <mvc:default-servlet-handler/>
12     <!--    mvc註解驅動-->
13     <mvc:annotation-driven/>
14     <!--    檢視解析器-->
15     <bean id="internalResoiurceViewResolver"
16           class="org.springframework.web.servlet.view.InternalResourceViewResolver">
17         <property name="prefix" value="/WEB-INF/jsp/" />
18         <property name="suffix" value=".jsp" />
19     </bean>
20 </beans>

 

三、手動編寫過濾器,過濾亂碼

注意:如果使用get傳送請求即使不加過濾器也不會亂碼,只有使用post才需要加過濾器

1、新建一個過濾器

public class EncodingFilter implements Filter {
    public void init(FilterConfig filterConfig) throws ServletException {
    }

    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        servletRequest.setCharacterEncoding("utf-8");
        servletResponse.setCharacterEncoding("utf-8");
        filterChain.doFilter(servletRequest,servletResponse);
    }

    public void destroy() {
    }
}

 

2、在web.xml中新增如下程式碼,注意url-pattern必須時“/*”,因為“/"會過濾掉jsp

    <filter>
        <filter-name>encoding</filter-name>
        <filter-class>com.han.filter.EncodingFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>encoding</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

 

3、直接使用springmvc自帶的過濾器 

    <filter>
        <filter-name>encoding</filter-name>
        <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
        <init-param>
            <param-name>encoding</param-name>
            <param-value>utf-8</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>encoding</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

 

四、編寫程式碼

1、建立user類

 1 package com.han.entity;
 2 
 3 public class User {
 4     public String getName() {
 5         return name;
 6     }
 7 
 8     public void setName(String name) {
 9         this.name = name;
10     }
11 
12     public int getAge() {
13         return age;
14     }
15 
16     public void setAge(int age) {
17         this.age = age;
18     }
19 
20     public String name;
21     public int age;
22 }

2、建立HelloController

 1 package com.han.controller;
 2 
 3 import com.han.entity.User;
 4 import org.springframework.stereotype.Controller;
 5 import org.springframework.ui.Model;
 6 import org.springframework.web.bind.annotation.RequestMapping;
 7 
 8 @Controller
 9 @RequestMapping("h1")
10 public class HelloController {
11 
12     @RequestMapping("/hello")
13     public String hello(Model model){
14 
15         model.addAttribute("msg","hello,spring");
16 
17         return "hello";//會被檢視解析器處理,找到 hello.jsp
18     }
19 
20     @RequestMapping("/getEntity")
21     public String getEntity(User user,Model model){
22         System.out.println(user.name);
23         model.addAttribute("msg",user.name+":"+user.age);
24         return "hello";
25     }
26 }

3、編寫index.jsp

 1 <%--
 2   Created by IntelliJ IDEA.
 3   User: han
 4   Date: 2022/4/15
 5   Time: 22:41
 6   To change this template use File | Settings | File Templates.
 7 --%>
 8 <%@ page contentType="text/html;charset=UTF-8" language="java" %>
 9 <html>
10   <head>
11     <title>$Title$</title>
12   </head>
13   <body>
14   <form action="${pageContext.request.contextPath}/h1/getEntity" method="post">
15     姓名:<input type="text" name="name"><br/>
16     年齡:<input type="text" name="age"><br/>
17     <input type="submit" value="提  交">
18   </form>
19   </body>
20 </html>

4、編寫hello.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
${msg}
</body>
</html>