qq_37634803
牧雨丿
2017-07-11 12:35
采纳率: 100%
浏览 1.3k
已采纳

ssm框架可以通过地址栏访问到后台但是前往前台会警告,并且访问不到!!

toLogin>>>>>>>>>>>>>>>>>>>>>>>>>>>
七月 11, 2017 8:10:01 下午 org.springframework.web.servlet.DispatcherServlet noHandlerFound
警告: No mapping found for HTTP request with URI [/shopping/WEB-INF/view/user/login.jsp] in DispatcherServlet with name 'springMvc'
上面是警告内容和运行后台代码的一个打印输出语句,可以访问进入后台以及运行代码但是去不了前台。我是新手希望各位大佬帮忙。找了好几个小时了。

下面是配置文件

springMvc-servlet.xml的内容

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

           <mvc:annotation-driven/>

           <context:component-scan base-package="com.dzl.ssm.web"/>

           <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" 
                p:prefix="/WEB-INF/view/"
                p:suffix=".jsp"
           />
</beans>

beans.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:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context.xsd">
        <context:component-scan base-package="com.dzl.ssm"/>
        <context:property-placeholder location="classpath:jdbc.properties"/>
        <bean id="dataSource" destroy-method="close" class="org.apache.commons.dbcp.BasicDataSource">
            <property name="driverClassName" value="${jdbc.Driver}"/>
            <property name="url" value="${jdbc.url}"/>
            <property name="username" value="${jdbc.username}"/>
            <property name="password" value="${jdbc.password}"/>
        </bean>
        <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
            <property name="dataSource" ref="dataSource"/>
            <property name="configLocation" value="classpath:mybatis-config.xml"/>
        </bean>

        <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
            <property name="basePackage" value="com.dzl.ssm.mapper"/>
        </bean>
</beans>

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">
  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:beans.xml</param-value>
  </context-param>
  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener
    </listener-class>
  </listener>
  <servlet>
    <servlet-name>springMvc</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>springMvc</servlet-name>
    <url-pattern>/*</url-pattern>
  </servlet-mapping>
</web-app>

controller代码

 package com.dzl.ssm.web;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.dzl.ssm.service.TextService;

@Controller
//请求映射
@RequestMapping("/text")
public class TextController {
    @Autowired
    private TextService textService;

    @RequestMapping("/list")
    public String getList(){
        System.out.println("list>>>>>>>>>>>>>>>>>>>>>>>>>>>");
        return "user/list";
    }

    @RequestMapping("/toLogin")
    public String toLogin(){
        System.out.println("toLogin>>>>>>>>>>>>>>>>>>>>>>>>>>>");

        return "user/login";
    }
}
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

4条回答 默认 最新

  • wu_0916
    竖心旁的情 2017-07-12 01:26
    已采纳

    拦截出现了问题~~~
    在web.xml加上这一堆看看

    default
    *.css

    <servlet-mapping>
        <servlet-name>default</servlet-name>
        <url-pattern>*.gif</url-pattern>
    
    </servlet-mapping>
    
    <servlet-mapping>
        <servlet-name>default</servlet-name>
        <url-pattern>*.jpg</url-pattern>
    </servlet-mapping>
    
    <servlet-mapping>
        <servlet-name>default</servlet-name>
        <url-pattern>*.js</url-pattern>
    </servlet-mapping>
    
    点赞 评论
  • wu_0916
    竖心旁的情 2017-07-12 01:27


    default
    *.css

    <servlet-mapping>
        <servlet-name>default</servlet-name>
        <url-pattern>*.gif</url-pattern>
    
    </servlet-mapping>
    
    <servlet-mapping>
        <servlet-name>default</servlet-name>
        <url-pattern>*.jpg</url-pattern>
    </servlet-mapping>
    
    <servlet-mapping>
        <servlet-name>default</servlet-name>
        <url-pattern>*.js</url-pattern>
    </servlet-mapping>  
    
    点赞 评论
  • wu_0916
    竖心旁的情 2017-07-12 01:27
    <servlet-mapping>
        <servlet-name>default</servlet-name>
        <url-pattern>*.css</url-pattern>
    </servlet-mapping>
    
    点赞 评论
  • BigHanson
    BigHanson 2017-07-12 04:15

    额,这不是提示找不到页面吗。 你确定web-inf view user 下有 login.jsp 页面没有

    点赞 评论

相关推荐