最近学习spring,在网上找了一个简单登陆的DEMO,弄好后文件路径是这样的
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" xmlns:web="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_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>SpringDemo</display-name>
<context-param>
<param-name>webAppRootKey</param-name>
<param-value>SpringDemo.webapp.root</param-value>
</context-param>
<!-- 指定log4j配置文件的位置 -->
<!-- WebApplicationContext需要使用日志功能,放在Spring配置的前面 -->
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>classpath:log4j.xml</param-value>
</context-param>
<!-- -->
<context-param>
<param-name>log4fRefreshInterval</param-name>
<param-value>60000</param-value>
</context-param>
<!-- 指定Spring配置文件 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<!-- 定义Web容器监听器,监听器负责完成IoC容器在Web环境中的启动工作 -->
<!-- IoC容器启动过程就是建立上下文的过程 -->
<!-- ContextLoaderListener启动的上下文为根上下文 -->
<!-- ContextLoaderListener实现了ServletContextListener接口 -->
<!-- ContextLoaderListener->ContextLoader:1,载入IoC容器到Web容器;2,实例化WebApplicationContext -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- 配置log4j的监听器 -->
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
<!-- DispatcherServlet起着分发请求的作用,Spring MVC的核心 -->
<!-- ContextLoaderListener初始化完成后,Web容器开始初始化DispatcherServlet -->
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/dispatcherServlet.xml</param-value>
</init-param>
</servlet>
<!-- 指定需要处理的http请求 -->
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>/WEB-INF/views/login.jsp</welcome-file>
</welcome-file-list>
</web-app>
现在网页输入localhost:8080/bysj 能到index.jsp,我要怎么样才能让他直接到login.jsp呢?应该在哪里配置?还有可以直接localhost:8080就进入首页吗?
刚刚学习所以不太懂,好心人帮帮忙啊~~~~~急急急~~~~
<welcome-file-list>
<welcome-file>login.jsp</welcome-file>
</welcome-file-list>
最底下就是配置你项目首页的!
localhost:8080 要进入首页的话,要把编译后的项目放入Tomcat 的root里面,然后再配置
/WEB-INF/views/index.jsp
<welcome-file-list>
<welcome-file>/WEB-INF/views/login.jsp</welcome-file>
</welcome-file-list>
改成
<welcome-file-list>
<welcome-file>views/login.jsp</welcome-file>
</welcome-file-list>
这样就行了
修改你的tomcat配置文件server.xml,将Context 标签中的path设置到根目录,免项目名访问。
<Context path="/" docBase="D:\bysj" debug="0" reloadable="true">
我的index.jsp是放在WebRoot目录下的,和WEB-INF同级。除了web.xml里的welcome-file有关系,和我其他两个XML文件会有关联吗??需要那两个文件的代码吗
在dispatcherServlet.xml里有这个,不知道有没有影响
<!-- 对模型视图名称的解析,在请求时模型视图名称添加前后缀,将ModelAndView解析为具体页面 -->
<!-- 使用了JstlView作为视图解析器。同时,指定前缀路径为"/WEB-INF/views/",后缀路径为".jsp
Spring容器将会在这个路径中寻找匹配的jsp文件! -->
<bean id="jstlViewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver"
p:prefix="/WEB-INF/views/"
p:suffix=".jsp" />
</beans>
然后tomcat的context.xml里面有
<Context>
<!-- Default set of monitored resources. If one of these changes, the -->
<!-- web application will be reloaded. -->
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<WatchedResource>${catalina.base}/conf/web.xml</WatchedResource>
<!-- Uncomment this to disable session persistence across Tomcat restarts -->
<!--
<Manager pathname="" />
-->
<!-- Uncomment this to enable Comet connection tacking (provides events
on session expiration as well as webapp lifecycle) -->
<!--
<Valve className="org.apache.catalina.valves.CometConnectionManagerValve" />
-->
</Context>
会有影响吗?
你更改完后,先把你原来部署的项目删掉,重新部署下就能条到login.jsp页面上了