Skip to content

Commit

Permalink
1.使前后台能完全联通
Browse files Browse the repository at this point in the history
2.前后台使用json进行通信
  • Loading branch information
lengque committed Aug 28, 2015
1 parent 4f83d51 commit 475bc69
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 31 deletions.
Binary file not shown.
Binary file not shown.
74 changes: 57 additions & 17 deletions SSHProject/WebContent/WebApp/web/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!DOCTYPE html>
<html lang="zh-CN">

<head>
Expand All @@ -7,27 +7,67 @@
<meta name="description" content="">
<meta name="viewport" content="width=device-width">
<title>欢迎登录后台管理系统</title>
<link href="WebApp/lib/css/style.css" rel="stylesheet" type="text/css" />
<style>
span.warn{
color:red;
padding-left: 45px;
}
</style>
<script language="JavaScript" src="WebContent/WebApp/js/jquery.js">
function sub(){
alert(1);
var userName = "zhangsan";
alert(userName);
$.ajax({
url : "login.action",
type : "post",
data : "userName=" + userName,
success : function(data, textStatus) {
alert(data);
}
});
}
</script>
<script language="JavaScript" src="WebApp/lib/js/jquery.js"></script>
<script src="WebApp/lib/js/common.js" type="text/javascript"></script>
<script language="javascript">
$(function() {
$('.loginbox').css({
'position': 'absolute',
'left': ($(window).width() - 692) / 2
});
$(window).resize(function() {
$('.loginbox').css({
'position': 'absolute',
'left': ($(window).width() - 692) / 2
});
})
var username = $("#username"), pwd = $("#password");

$("#login").click(
function(){
var userName = $("#username"), pwd = $("#password"), rmb = $("#rmb");
if(userName.val()!=="" && pwd.val()!==""){
if(rmb.is(":checked")){
localStorage.setItem("logonName", userName);
}

$.ajax({
url : "login.action",
type : "post",
data : {"userName":"123"},
dataType:'json',
success : function(data, textStatus) {
alert(data);
}
});
}else{
return;
}
});

username.bind("blur", function(){
if(username.val().trim() === ""){
$("#username").next().show();
}else{
$("#username").next().hide();
}
});
pwd.bind("blur", function(){
if(pwd.val().trim() === ""){
$("#password").next().show();
}else{
$("#password").next().hide();
}
});
});
</script>
</head>

<body style="background-color:#1c77ac; overflow:hidden;">
Expand Down Expand Up @@ -56,7 +96,7 @@
<span class="warn" style="display:none">密码不正确</span>
</li>
<li>
<input name="login" id="login" type="button" onclick="sub();" class="loginbtn" value="登录"/>
<input name="login" id="login" type="button" class="loginbtn" value="登录"/>
<label>
<input name="rmb" id="rmb" type="checkbox" value="" checked="checked" />记住密码</label>
<label><a href="#">忘记密码?</a></label>
Expand Down
35 changes: 24 additions & 11 deletions SSHProject/src/controller/UserController.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.apache.commons.logging.*;
import org.apache.struts2.interceptor.ServletResponseAware;
import org.apache.struts2.interceptor.SessionAware;

import service.UserService;
Expand All @@ -19,7 +22,7 @@

import converter.UserConverter;

public class UserController extends ActionSupport implements SessionAware {
public class UserController extends ActionSupport implements SessionAware,ServletResponseAware {

private UserService userService;
private UserConverter userConverter;
Expand All @@ -28,6 +31,8 @@ public class UserController extends ActionSupport implements SessionAware {
protected Map<String, Object> session;
private Log logger = LogFactory.getLog(this.getClass().getName());
private String userName;
private javax.servlet.http.HttpServletResponse response;

/**
* <p>查询分页数据</p>
* @parm pageBean
Expand Down Expand Up @@ -101,8 +106,8 @@ public String addNewUser() {
* login
*/
public String login() {
System.out.println(userName);
try {

if(logger.isDebugEnabled()){
logger.debug("开始登录~~~");
}
Expand All @@ -111,8 +116,8 @@ public String login() {
User user = userConverter.loginConverter(userDTO);

// 2.get the user info from database
User dbUser = userService.login(user);

//User dbUser = userService.login(user);
User dbUser = new User();
// 3.convert the user to userDTO
userDTO = userConverter.reverseConverter(dbUser);

Expand All @@ -123,7 +128,7 @@ public String login() {
if(logger.isDebugEnabled()){
logger.info("登录成功");
}
return SUCCESS;

} catch (BaseException e) {
session.put(UserUtil.User_Login, null);
session.put(UserUtil.User_Is_Login,false);
Expand All @@ -133,7 +138,7 @@ public String login() {
} catch (Exception e) {
e.printStackTrace();
}

return SUCCESS;
}

Expand Down Expand Up @@ -186,7 +191,6 @@ public String modifyInfo() {
} catch (Exception e) {
e.printStackTrace();
}

return SUCCESS;
}

Expand Down Expand Up @@ -230,9 +234,9 @@ public String deleteUser() {
/**
* set userDTO
*/
public UserDTO getUserDTO() {
/*public UserDTO getUserDTO() {
return userDTO;
}
}*/

/**
* get userDTO
Expand Down Expand Up @@ -268,15 +272,24 @@ public void setSession(Map<String, Object> session) {
this.session = session;
}

public PageBean<User> getPage() {
/*public PageBean<User> getPage() {
return page;
}
public void setPage(PageBean<User> page) {
this.page = page;
}
}*/

public void setUserName(String userName){
this.userName = userName;
}

public String getUserName(){
return this.userName;
}

@Override
public void setServletResponse(HttpServletResponse response) {
this.response = response;
}
}
9 changes: 6 additions & 3 deletions SSHProject/src/struts_user.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@

<struts>
<!--User module start -->
<package name="loginAndRegister" namespace="/" extends="struts-default">
<package name="loginAndRegister" namespace="/" extends="json-default">
<!-- 登陆 -->
<action name="login" class="userController" method="login">
<result name="success">/Resources/pages/main.jsp</result>
<result name="login">/Resources/pages/login.jsp</result>
<result type="json">
<param name="root">userName</param>
</result>
<!-- <result name="success">/Resources/pages/main.jsp</result>
<result name="login">/Resources/pages/login.jsp</result> -->
</action>

<!-- 注册 -->
Expand Down

0 comments on commit 475bc69

Please sign in to comment.