67,513
社区成员
发帖
与我相关
我的任务
分享
package com.scms.admin.web;
import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import com.scms.dao.service.ILoginService;
import com.scms.model.Admin;
@Controller
@RequestMapping("/login")
public class LoginController {
@Resource
public ILoginService loginService;
// 登陆功能
@RequestMapping(value = "/loginS", method = RequestMethod.POST)
public String loginS(Model model, HttpSession session, String username,
String password, String yzm) {
String kaptchaExpected = (String) session
.getAttribute(com.google.code.kaptcha.Constants.KAPTCHA_SESSION_KEY);
Admin admin = loginService.LoginS(username, password);
if (admin==null) {
model.addAttribute("MessError", "用户名与密码不正确!");
return "Admin/login";
} else if (!(kaptchaExpected.equals(yzm)) && kaptchaExpected != yzm) {
model.addAttribute("MessError", "验证码不正确!");
return "Admin/login";
} else {
return "Admin/main";
}
}
}
<?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"
xmlns:mvc="http://www.springframework.org/schema/mvc"
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.1.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd">
<!-- 静态文件 -->
<mvc:resources location="/static/" mapping="/static/**" />
<mvc:annotation-driven />
<!--注解说明 -->
<context:annotation-config />
<!-- 把标记了@Controller注解的类转换为bean -->
<context:component-scan base-package="com.scms.admin.web" />
<!-- 启动Spring MVC的注解功能,完成请求和注解POJO的映射 请求映射 -->
<bean
class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />
<!--在这里配置后缀名jsp和视图解析器。。 -->
<bean id="viewResolverCommon"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/view/" />
<property name="suffix" value=".jsp" />
<property name="ViewClass">
<value>org.springframework.web.servlet.view.InternalResourceView</value>
</property>
<property name="order" value="1"></property>
</bean>
<!-- FreeMarker视图解析 。在这里配置后缀名ftl和视图解析器。。 -->
<bean id="viewResolver"
class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">
<property name="viewClass"
value="org.springframework.web.servlet.view.freemarker.FreeMarkerView" />
<property name="contentType" value="text/html;charset=UTF-8" />
<property name="cache" value="true"/>
<property name="suffix" value=".ftl" />
<property name="order" value="0"/>
</bean>
<!-- 配置FreeMarker模板路径 -->
<bean id="freemarkerConfig" class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
<property name="templateLoaderPath">
<value>/WEB-INF/view/</value>
</property>
<property name="freemarkerVariables">
<map>
<entry key="xml_escape" value-ref="fmXmlEscape" />
</map>
</property>
<property name="defaultEncoding">
<value>utf-8</value>
</property>
<property name="freemarkerSettings">
<props>
<prop key="template_update_delay">3600</prop>
</props>
</property>
</bean>
<bean id="fmXmlEscape" class="freemarker.template.utility.XmlEscape"/>
</beans>
<IFRAME style="OVERFLOW: visible" id="main" name="main" src="default.jsp" frameBorder=0 width="100%" scrolling="yes" height="100%"></IFRAME>