qq_38903478
qq_38903478
采纳率0%
2020-05-22 15:42

Myeclipse上访问WEB-INF下面的页面,直接用端口号和项目名访问,都配置好了,运行页面出现空白,控制台也没报错是怎么回事,求大神回复一下,急!!!

web.xml配置如下:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 
    xmlns="http://java.sun.com/xml/ns/javaee" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
    http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

      <!-- 配置spring核心监听器,默认会以 /WEB-INF/applicationContext.xml作为配置文件 -->
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <!-- contextConfigLocation参数用来指定Spring的配置文件 -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/applicationContext.xml</param-value>
    </context-param>

    <!-- 定义Spring MVC的前端控制器 -->
  <servlet>
    <servlet-name>springmvc</servlet-name>
    <servlet-class>
        org.springframework.web.servlet.DispatcherServlet
    </servlet-class>
    <init-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>/WEB-INF/springmvc-config.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <!-- 让Spring MVC的前端控制器拦截所有请求 -->
  <servlet-mapping>
    <servlet-name>springmvc</servlet-name>
    <url-pattern>/</url-pattern>
  </servlet-mapping>

  <!-- 编码过滤器 -->
  <filter>
        <filter-name>characterEncodingFilter</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>characterEncodingFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

  <error-page>
    <error-code>404</error-code>
    <location>/404.html</location>
  </error-page>

      <welcome-file-list>

  </welcome-file-list>
</web-app>

springmvc-config.xml如下:
<?xml version="1.0" encoding="UTF-8"?>
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.2.xsd">

<!-- 自动扫描该包,SpringMVC会将包下用了@controller注解的类注册为Spring的controller -->

<!-- 设置默认配置方案 -->
mvc:annotation-driven/

mvc:default-servlet-handler/

   <mvc:interceptors>
     <mvc:interceptor>
        <mvc:mapping path="/*"/>
           <mvc:exclude-mapping path="/WEB-INF/jsp/Main.jsp"/>
           <mvc:exclude-mapping path="/404.html"/>
        <mvc:exclude-mapping path="/login"/>
        <bean class="com.jxgl.until.LoginInterceptor" /> 
    </mvc:interceptor>
  </mvc:interceptors>



<!-- 视图解析器  -->
 <bean id="viewResolver"
      class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
    <!-- 前缀 -->
    <property name="prefix" value="/WEB-INF/jsp"/>

    <!-- 后缀 -->
    <property name="suffix" value=".jsp"/>
</bean>

<bean id="multipartResolver" class="org.springframework.web.mult![图片说明](https://img-ask.csdn.net/upload/202005/22/1590133076_502751.png)

ipart.commons.CommonsMultipartResolver">

<property name="maxUploadSize">
<value>10485760</value></property>
<property name="defaultEncoding">
<value>UTF-8</value>
</property>
</bean>

UserController如下:
package com.gw.Controller;
import java.util.HashMap;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.gw.Domain.User;
import com.gw.Service.UserService;
import com.gw.until.PageManage;
//控制层
//控制层调用业务层
//业务层调用数据访问层
@Controller
@RequestMapping(value="/")
public class UserController {
    @Autowired
    @Resource(name="userService")
    UserService userService;
    int pageSize=3;
        //将所有的jsp访问都通过控制器来访问,避免非系统用户直接访问本系统
    @RequestMapping(value="/")
    public String Initial(){
        return "Main";
    }   
    @RequestMapping(value="Enter",method=RequestMethod.GET)
    public String EnterForm(){
        return "Enter";
    }
    @RequestMapping("{pathname}")
        public String pathname(@PathVariable String pathname){
            return pathname;
        }
部署运行tomcat,浏览器输入http://localhost:8080/GW控制台没出错,页面也没有错误说明,就是空白的,换了好几个浏览器都是这样,页面是这样的

![图片说明](https://img-ask.csdn.net/upload/202005/22/1590133300_346347.png)
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

相关推荐