一次完整请求的日志

一次完整请求的日志:



各种配置文件:

spring-mvc.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" rel="nofollow"" target="_blank">http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc" rel="nofollow"" target="_blank">http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context" rel="nofollow"" target="_blank">http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop" rel="nofollow"" target="_blank">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>
<bean class="org.springframework.http.converter.ByteArrayHttpMessageConverter"/>
<bean class="org.springframework.http.converter.FormHttpMessageConverter"/>
<bean class="org.springframework.http.converter.xml.SourceHttpMessageConverter"/>
<bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"/>
</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/>
</beans>
spring-mybatis.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" rel="nofollow"" target="_blank">http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" rel="nofollow"" target="_blank">http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx" rel="nofollow"" target="_blank">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"/>
</beans>
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>密 码</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.java:

复制代码
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";
}
}
}

转载于:https://www.cnblogs.com/rtjherty848/p/8601727.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值