天津东软实训第五天

今天主要学习了下面几个方面的内容:

1、MapReduce实战,读取气温。从十个文件中获取气温,并计算平均值。

2、通过HDFS读取MapReduce生成的文件,并把数据传入数据库。

3、SpringMVC的原理,使用,配置

下面回顾一下SpringMVC的使用:

首先,新建war模式的maven项目,导入需要的包:

spring-context

 

spring-webmvc

 

jstl

然后,此时会报错,是因为缺少web.xml文件,因此,在webapp目录下新建WEB-INF目录,并在WEN-INF目录下,新建web.xml文件。web.xml内容如下:

<?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">
	<servlet>
		<servlet-name>springmvc</servlet-name>
		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
		<init-param>
			<param-name>namespace</param-name>
			<param-value>springmvc</param-value>
		</init-param>
		
		<load-on-startup>1</load-on-startup>
	</servlet>
	<servlet-mapping>
	<servlet-name>springmvc</servlet-name>
		<url-pattern>/</url-pattern>
	</servlet-mapping>
</web-app>

在WEB-INF目录下新建springmvc.xml文件:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
	xmlns:p="http://www.springframework.org/schema/p"
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:util="http://www.springframework.org/schema/util" 
	xmlns:mvc="http://www.springframework.org/schema/mvc"
	xmlns:tx="http://www.springframework.org/schema/tx"
	xmlns:aop="http://www.springframework.org/schema/aop"
	xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
       http://www.springframework.org/schema/context 
       http://www.springframework.org/schema/context/spring-context-4.0.xsd
       http://www.springframework.org/schema/util 
       http://www.springframework.org/schema/util/spring-util-4.0.xsd 
       http://www.springframework.org/schema/mvc 
       http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
       http://www.springframework.org/schema/tx
       http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
        http://www.springframework.org/schema/aop
       http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
">
	<mvc:annotation-driven></mvc:annotation-driven>
	<context:component-scan base-package="com.test"></context:component-scan>
	<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
		<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"></property>
		<property name="prefix" value="/WEB-INF/pages/"></property>
		<property name="suffix" value=".jsp"></property>
	</bean>
</beans>

编写测试类springmvc:

 

package com.test;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class springmvc {
	@RequestMapping("/index")
	public String index(){
		System.out.println("11111111");
		return "abc";
	}

}

在WEB-INF下新建pages文件夹,在pages文件夹下新建abc.jsp:

<%@ 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>
</head>
<body>
adfadfsasdfasdfsadf
</body>
</html>

 启动tomcat服务器,在网页上运行。OK!配置完成。 

  

 

  

 

posted @ 2018-07-14 12:48  YOUNG111  阅读(380)  评论(0编辑  收藏  举报