最近想整合S2SH,采用的是spring4+hibernate4+struts2+maven+MySQL+jdk1.8+tomcat7.
<constant name="struts.objectFactory" value="spring"/> <constant name="struts.devMode" value="true"/> <constant name="struts.configuration.xml.reload" value="true"/> <constant name="struts.serve.static.browserCache" value="false"/> <constant name="struts.i18n.encoding" value="UTF-8"/> <constant name="struts.i18n.reload" value="true"/> <constant name="struts.multipart.maxSize" value="104857600"/> <constant name="struts.enable.DynamicMethodInvocation" value="false"/> <package name="common" extends="struts-default"></package> <package name="login" namespace="/login" extends="common"> <action name="login" class="userLogin"> <result name="loginFail">fail.jsp</result> <result name="success">index.jsp</result> </action> </package>
<context:annotation-config/> <context:component-scan base-package="com.value.yun.modules" />
package com.value.yun.modules.controller; import com.opensymphony.xwork2.ActionSupport; import com.value.yun.common.base.Encryption; import com.value.yun.modules.entity.User; import com.value.yun.modules.service.UserService; import com.value.yun.utils.StringUtils; import org.apache.struts2.ServletActionContext; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import javax.servlet.http.HttpServletRequest; /** * Created by 丽 on 2015/4/16. */ @Controller public class LoginController extends ActionSupport{ public LoginController(){ System.out.println("============login controller constructor=========================="); } private User user; @Autowired private UserService userService; public User getUser() { return user; } public void setUser(User user) { this.user = user; } @RequestMapping(value = "userLogin") public String login(){ HttpServletRequest request = ServletActionContext.getRequest(); if (user==null){ request.setAttribute("loginFail","对象为空"); return "loginFail"; } if(StringUtils.isBlank(user.getLoginName())){ request.setAttribute("loginFail","登录账号为空"); return "loginFail"; } if (StringUtils.isBlank(user.getPassword())){ request.setAttribute("loginFail","登录密码为空"); return "loginFail"; } request.setAttribute("loginName",user.getLoginName()); request.setAttribute("password", Encryption.encrytMD532(user.getPassword())); return "success"; } }
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <html> <head> <meta name="decorator" content="default"/> <title>欢迎来到登录界面</title> </head> <body> <h2>Hello World!</h2> <form action="${baseUrl}/login/login" method="post" class="loginForm"> <table> <tr> <th>账号:</th> <td><input type="text" name="user.loginName"></td> </tr> <tr> <th>密码:</th> <td><input type="password" name="user.password"></td> </tr> <tr> <td><button type="submit">登录</button></td> <td><button type="reset">重置</button></td> </tr> </table> </form> ${loginName}<br> ${password} </body> </html>