上一章写到pom.xml有一个报错,说找不到web.xml文件。确实是这样的,因为我们用maven搭建的web层里就是没有这个文件。我们能看到,webapp文件夹里是空的。

没有,就想办法把它弄出来。

一、右键项目>>>>Java EE Tools>>>>Generate Deployment Descriptor Stub

  

  然后就出来了。

  参考:https://www.cnblogs.com/pjlhf/p/8782651.html

二、在webapp目录下新建一个index.jsp

  1、根据默认的路径,就是要在这里建一个,才能读取到。

  2、会发现一个bug

    Multiple annotations found at this line:
    - The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path

  3、这个时候去Java Build Path 里面配置Server Runtime 为Tomcat 也可以解决问题,但是……

    我们回想上一章,父项目的pom.xml 里已经配置了Servlet。

    找了一下,发现这个是在dependencyManagement节点里的。

    要用的话,就需要在子项目中的pom.xml再写一遍。

    或者在dependencyManagement外面的那个dependencies再写一遍。

  

  4、这个时候就能运行成功了。


  但我还是想笑一下/捂脸,说好是ssh项目的搭建嘛,到时候肯定用的struts2啊,servlet就不需要了,以上操作就白废了。

  

三、配置web.xml

  阿豪聊干货:

  https://www.cnblogs.com/hafiz/p/5715523.html

  下面的东西先配着,下一章再配SSH

  1、配Spring初始化参数

     <context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:applicationContext.xml
</param-value>
</context-param>

  2、配openSessionInView

     <filter>
<filter-name>openSessionInView</filter-name>
<filter-class>common.toolkit.java.orm.hibernate.OpenSessionInViewFilter</filter-class>
<init-param>
<param-name>singleSession</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>openSessionInView</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

  3、配Struts2

 1     <filter>
2 <filter-name>struts2</filter-name>
3 <filter-class>com.wisdombud.jrj.actions.filter.MyStrutsFilter
4 </filter-class>
5 </filter>
6 <filter-mapping>
7 <filter-name>struts2</filter-name>
8 <url-pattern>/*</url-pattern>
9 <dispatcher>REQUEST</dispatcher>
10 <dispatcher>FORWARD</dispatcher>
11 <dispatcher>INCLUDE</dispatcher>
12 </filter-mapping>

  4、配监听

     <listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>

  5、配session时长(30分钟)

     <session-config>
<session-timeout>30</session-timeout>
</session-config>

  6、配置错误页面

     <error-page>
<exception-type>java.lang.Throwable</exception-type>
<location>/500.jsp</location>
</error-page>
<error-page>
<error-code>500</error-code>
<location>/500.jsp</location>
</error-page>
<error-page>
<error-code>404</error-code>
<location>/404.jsp</location>
</error-page>

  

  当然,前面明明是可以跑起来的,配完这些就跑不起来了,那是因为这里配了很多文件,但是这些文件都是找不到的,我们还没配嘛。

  下一章,配SSH整合。

SSH项目搭建(五)——web.xml文件配置的更多相关文章

  1. springmvc 项目完整示例07 设置配置整合springmvc springmvc所需jar包springmvc web.xml文件配置

    前面主要是后台代码,spring以及mybatis的整合 下面主要是springmvc用来处理请求转发,展现层的处理 之前所有做到的,完成了后台,业务层和持久层的开发完成了 接下来就是展现层了 有很多 ...

  2. web.xml 文件配置01

    web.xml 文件配置01   前言:一般的web工程中都会用到web.xml,方便开发web工程.web.xml主要用来配置Filter.Listener.Servlet等.但是要说明的是web. ...

  3. Spring整合Hibernate的XML文件配置,以及web.xml文件配置

    利用Spring整合Hibernate时的XML文件配置 applicationContext.xml <?xml version="1.0" encoding=" ...

  4. SSH web.xml文件配置

    启动一个WEB项目的时候, WEB容器会去读取它的配置文件web.xml web.xml中配置的加载优先级:context-param -> listener -> filter -> ...

  5. Struts2 web.xml文件配置

    在导入了项目需要使用的核心jar包之后需要在web.xml中配置Struts. 1. Struts2的知识点普及: Struts2共有5类配置文件,分别罗列如下: 1), Web.xml; 在没有使用 ...

  6. web.xml文件配置详解以及实例说明

    1.web.xml学名叫部署描述符文件,是在Servlet规范中定义的,是web应用的配置文件. 2.部署描述符文件就像所有XML文件一样,必须以一个XML头开始.这个头声明可以使用的XML版本并给出 ...

  7. spring mvc学习笔记(一)web.xml文件配置的一点重要信息

    通过这个web.xml文件可以看出,所有的*.shtml的请求,都会被springmvc这个servlet处理.这里如果没有指定contextConfigLocation这个参数,将会按照默认规则在c ...

  8. web.xml文件配置模板

    直接贴完整代码,当然,spring的核心控制器依赖包需要通过mean提前配置 <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.// ...

  9. web项目直接在浏览器上访问不需要带.jsp,直接ip地址加项目名 在web.xml里配置

    web.xml最上方 <welcome-file-list> <welcome-file> /view/login.jsp </welcome-file> < ...

随机推荐

  1. 《剑指offer》第三_一题(找出数组中重复的数字,可改变数组)

    // 面试题3(一):找出数组中重复的数字 // 题目:在一个长度为n的数组里的所有数字都在0到n-1的范围内.数组中某些数字是重复的,但不知道有几个数字重复了, // 也不知道每个数字重复了几次.请 ...

  2. ubuntu 安装 openssh-server,xinetd,vmware tools

    ●安装SSH服务 ●判断是否安装ssh服务,通过如下命令:ps -e|grep ssh 1, sudo apt-get update --->软件的更新地址变了,需要更新本机的sources.l ...

  3. HDU 6114 Chess

    Chess 思路:求C(n,m),除法取余用乘法逆元算. 代码: #include<bits/stdc++.h> using namespace std; #define ll long ...

  4. English trip V1 - 辅导课 VOCABULARY BRUSH UP(1-6) 词汇刷新 SA:Winona

    1.How Do you Feel Now?            形容词  adj.  = adjective                     Describe people and thi ...

  5. (GoRails) 如何去掉form输入框头尾的空格;何时用callbacks,gem;

    视频:https://gorails.com/episodes/when-callbacks-and-adding-dependencies-are-good?autoplay=1 主题:应当在什么时 ...

  6. 3-22 Ruby 编码规则(个人整理)

    编码规则 https://github.com/thoughtbot/guides/tree/master/style/ruby *Use a trailing comma after each it ...

  7. PHP导出为Word格式

    <?php $file = './html.doc'; $table = '<table width="100%"><tr><td>'.i ...

  8. Sergey's problem CodeForces - 1019C (图论,构造,神题)

    链接 大意: 给定有向图, 求选择一个点集$S$, 使得$S$任意两点不相连, 且对于不属于$S$的任意点$x$, 均存在$S$中的点$y$, 使得$d(x,y)<=2$, $d(x,y)$为从 ...

  9. POJ-1753 Flip Game (BFS+状态压缩)

    Description Flip game is played on a rectangular 4x4 field with two-sided pieces placed on each of i ...

  10. iOS UI-表格控制器(UITableView)-基本使用

    tableView的常见属性 cell的常见属性 一.一般情况 #import "ViewController.h" @interface ViewController ()< ...