10,607
社区成员
发帖
与我相关
我的任务
分享
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
<display-name>one</display-name>
<!-- 上面这些都是系统自动生成的,是固定的,目前还没有理解其作用。 -->
<!-- 制定首页
当用户在浏览器中输入的URL不包含某个servlet名或JSP页面时,welcome-file-list元素可指定显示的默认文件
PS:咱这个工程里基本没用 -->
<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控制跳转 ,所有的请求都会被此拦截。有了它就要在外面配置一个对应的xml。-->
<servlet>
<!-- 这个name是随便起的,但是要对应起来 -->
<servlet-name>two</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<!-- 这个地方的name与上面的对应才行,还有外面对应的xml文件要写成 two-servlet.xml必须对应。 -->
<servlet-name>two</servlet-name>
<url-pattern>/</url-pattern><!-- 这个地方的/代表全部请求 -->
</servlet-mapping>
<!-- 字符过滤器 ,在此工程中貌似是没用到。-->
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>utf8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name >
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
<?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:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<!-- 上边这些就是一些引用的文件种种,不用管它,照着来就行。 -->
<!-- 引用注解 -->
<mvc:annotation-driven/>
<!-- 自动扫描下面命名的包 ,扫描到注解@controller后,就访问那个后台java了。-->
<context:component-scan base-package="three"/>
<bean id="registry" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
<!-- java文件里return的名字就是在这里找/WEB-INF/jsp/(eight).jsp ,于是就找到了-->
<property name="prefix" value="/WEB-INF/jsp/"></property>
<property name="suffix" value=".jsp"></property>
</bean>
</beans>
package three;
import java.util.Map;
import org.springframework.stereotype.Controller; //你看,这里就用到了我们导入的包。
import org.springframework.web.bind.annotation.RequestMapping;
@Controller //这个就是前面xml文件里扫描到的类似连接进来的注解。
public class Four {
public String Name = "zhu";
//@RequestMapping”请求路径映射,如果标注在某个controller的类级别上,则表明访问此类路径下的
// 方法都要加上其配置的路径;最常用是标注在方法上,表明哪个具体的方法来接受处理某次请求。
@RequestMapping(value={"/","/zhu"}) //value值前后是否有“/”对请求的路径没有影响,即value="zhu" 、"/zhu"、"/zhu/"其效果是一样的
public String seven(Map<String,Object> a){
a.put("lalala", Name);
return "eight"; //这个地方return的值是将要寻找的jsp文件的名称,去哪儿找呢?
//就是去two-servlet。xml配置路径前面说的找eight.jsp。
}
}
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!-- 注意上边的默认字符集要改成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=ISO-8859-1">
<title>爱吃青菜的猪</title><!-- 这地方是显示在最上方标签位置的文字 -->
</head>
<body> <!-- body里面写的就是网页上显示的正文了。 -->
<!-- java 里用了个Map方法,使用具体信息自己去查。 -->
<p>这是后台里输出来的变量</p>
****************************************************************<br>
${lalala }<br>
</body>
</html>
<h1>下面是一张图片</h1>
<img src="<%=request.getContextPath()%>/five/tupian.jpg" /><br>
<!-- 中间那玩意是啥呀? 说实话 我也不清楚 O(∩_∩)O~ -->
<img src="/five/tupian.jpg" /><br>
<!-- 去掉也能显示 -->
<!-- 引用注解 -->
<mvc:annotation-driven/>
<!-- 自动扫描下面命名的包 ,扫描到注解@controller后,就访问那个后台java了。-->
<context:component-scan base-package="three"/>
<!-- 下面这行,静态文件访问路径权限,意思就是下面的location目录会跳过拦截直接访问,
(在这里写的five,six就是说WebContent的five,six文件夹里的所有东西都可以跳过拦截)
这是后面我要说的静态文件访问的问题用到的。 -->
<mvc:resources location="/five/" mapping="/five/**"/>
<bean id="registry" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
<!-- java文件里return的名字就是在这里找/WEB-INF/jsp/(eight).jsp ,于是就找到了-->
<property name="prefix" value="/WEB-INF/jsp/"></property>
<property name="suffix" value=".jsp"></property>
</bean>
</beans>
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!-- 注意上边的默认字符集要改成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=ISO-8859-1">
<title>爱吃青菜的猪</title><!-- 这地方是显示在最上方标签位置的文字 -->
</head>
<body> <!-- body里面写的就是网页上显示的正文了。 -->
<!-- java 里用了个Map方法,使用具体信息自己去查。 -->
<p>这是后台里输出来的变量</p>
****************************************************************<br>
${lalala }<br>
<h1>下面是一视频和一音乐</h1>
<embed src="five/yinyue.mp3" autostart="false" loop="true" width="300" height="70"> </embed>
<br>
<embed src="five/shipin.mp4" autostart="false" loop="true" width="500" height="300"> </embed>
<h1>下面是一张图片</h1>
<img src="<%=request.getContextPath()%>/five/tupian.jpg" /><br>
<!-- 中间那玩意是啥呀? 说实话 我也不清楚 O(∩_∩)O~ -->
<img src="/five/tupian.jpg" /><br>
<!-- 去掉也能显示 -->
</body>
</html>