Love琴笛 2018-03-19 03:51 采纳率: 0%
浏览 1357
已结题

项目运行没有报错,但是提交表单后无法找到controller

图片说明
一次完整请求的日志:
图片说明
我的各种配置:
spring-mvc.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"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd">
mvc:annotation-driven
mvc:message-converters




/mvc:message-converters
/mvc:annotation-driven

<!-- 使用annotation 自动注册bean,并保证@Required,@Autowired的属性被注入 -->
<mvc:annotation-driven/>
<context:component-scan base-package="com.commoninfo.user.controller">
    <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan>

<aop:aspectj-autoproxy proxy-target-class="true">
    <aop:include name="controllerAspect"/>
</aop:aspectj-autoproxy>


<!-- 避免IE执行AJAX时,返回JSON出现下载文件 -->
<!-- 支持JSON数据格式 -->
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
    <property name="messageConverters">
        <list>
            <ref bean="mappingJacksonHttpMessageConverter"/>
        </list>
    </property>
</bean>
<bean id="mappingJacksonHttpMessageConverter"
      class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
</bean>

<!-- 对模型视图名称的解析,即在模型视图名称添加前后缀 -->
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix" value="/WEB-INF/view/"/>
    <property name="suffix" value=".jsp"/>
</bean>
<!--处理静态资源-->
<mvc:default-servlet-handler/>

spring-mybatis.xml配置:
<?xml version="1.0" encoding="UTF-8"?>
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">

<!--引入属性文件-->
<context:property-placeholder location="classpath:/jdbc.properties"/>

<context:component-scan base-package="com.commoninfo.user.service"/>
<!--配置数据源-->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
    <property name="driverClass" value="${database.driver}"/>
    <property name="jdbcUrl" value="${database.url}"/>
    <property name="user" value="${database.username}"/>
    <property name="password" value="${database.password}"/>
    <property name="minPoolSize" value="1"/>
    <property name="maxPoolSize" value="20"/>
    <property name="maxIdleTime" value="1800"/>
    <property name="acquireIncrement" value="2"/>
    <property name="maxStatements" value="0"/>
    <property name="initialPoolSize" value="2"/>
    <property name="idleConnectionTestPeriod" value="1800"/>
    <property name="acquireRetryAttempts" value="30"/>
    <property name="breakAfterAcquireFailure" value="true"/>
    <property name="testConnectionOnCheckout" value="false"/>
</bean>

<!--mybatis文件-->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
    <property name="dataSource" ref="dataSource"/>
    <!--自动扫描entity目录-->
    <property name="configLocation" value="classpath:mybatis-config.xml"/>
    <property name="mapperLocations" value="classpath*:com/commoninfo/user/**/*.xml"/>
</bean>

<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
    <property name="basePackage" value="com.commoninfo.user.dao"/>
    <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>
</bean>

<!-- 配置事务管理器 -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    <property name="dataSource" ref="dataSource"/>
</bean>

<!-- 配置事物的注解方式注入 -->
<tx:annotation-driven transaction-manager="transactionManager"/>

 web.xml的配置:
 <!DOCTYPE web-app PUBLIC
        "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
        "http://java.sun.com/dtd/web-app_2_3.dtd" >

<web-app>
    <display-name>Archetype Created Web Application</display-name>
    <!-- Spring-mybatis的配置文件 -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:spring-mybatis.xml</param-value>
    </context-param>

    <servlet>
        <servlet-name>SpringMVC</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:spring-mvc.xml</param-value>
        </init-param>
        <load-on-startup>2</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>SpringMVC</servlet-name>
        <url-pattern>*.do</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>UTF-8</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>encodingFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

    <listener>
        <listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>
    </listener>

    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>

    <!--404错误页-->
    <error-page>
        <error-code>404</error-code>
        <location>/WEB-INF/view/404.jsp</location>
    </error-page>
</web-app>

index.jsp的内容:
<%--
  Created by IntelliJ IDEA.
  User: zhulongkun
  Date: 2018/3/18
  Time: 14:06
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8" %>
<html>
<head>
    <title>登录测试</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<div align="center">
    <form action="/test/dologin.do" method="post">
        <table>
            <tr>
                <td><label>用户名</label></td>
                <td><label>
                    <input type="text" name="username" style="width: 180px;"/>
                </label></td>
            </tr>
            <tr>
                <td><label>密&nbsp;码</label></td>
                <td><label>
                    <input type="password" name="password" style="width: 180px;"/>
                </label></td>
            </tr>
            <tr>
                <td><input type="submit" name="login" value="登录"/></td>
                <td><input id="registerBtn" type="button" name="register" value="注册"/></td>
            </tr>
        </table>
    </form>
</div>
</body>
</html>

controller的内容:
package com.commoninfo.user.controller;

import com.commoninfo.user.entity.User;
import com.commoninfo.user.service.UserService;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

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

/**
 * @author zhulongkun20@163.com
 * @date 2018/3/18 13:56
 */
@Controller
@RequestMapping("/test")
public class LoginController {
    private static Logger logger = Logger.getLogger(LoginController.class);
    @Resource
    private UserService userService;

    @RequestMapping(value = "/dologin.do")
    public String doLogin(HttpServletRequest httpServletRequest, Model model) {
        User user = userService.getUsersByUsername(
                httpServletRequest.getParameter("username")).get(0);
        logger.info("User的信息为:" + user.toString());
        if (userService.doUserLogin(user)) {
            model.addAttribute("successMsg", "登录成功!");
            model.addAttribute("username", user.getUsername());
            logger.info("successMsg:" + model.containsAttribute("successMsg"));
            logger.info("username:" + model.containsAttribute("username"));
            return "success";
        } else {
            model.addAttribute("failedMsg", "用户名或密码错误!");
            logger.info("failedMsg:" + model.containsAttribute("failedMsg"));
            return "failed";
        }
    }
}















  • 写回答

10条回答 默认 最新

  • SNOYC 2018-03-19 04:13
    关注

    是不是路径的问题,试试全路径呢

    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料