ssh框架整合入门登陆实例--------第四步web界面与Action实例设计

Action

package com.Action;
import com.Dao.UserDaoImpl;
import com.Entity.User;
import com.Service.UserServiceImpl;
import com.opensymphony.xwork2.Action;
import java.awt.event.ActionEvent;
import java.beans.PropertyChangeListener;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class AdduserAction implements Action {
    
    
    private int id;
    private static String userName;
    private static String password;

    public int getId() {
    
    
        return id;
    }

    public void setId(int id) {
    
    
        this.id = id;
    }

    public String getMessage() {
    
    
        return message;
    }

    public void setMessage(String message) {
    
    
        this.message = message;
    }

    private String message;
    public static String getUserName() {
    
    
        return userName;
    }
    public void setUserName(String userName) {
    
    
        AdduserAction.userName = userName;
    }
    public static String getPassword() {
    
    
        return password;
    }
    public void setPassword(String password) {
    
    
        AdduserAction.password = password;
    }
    @Override
    public String execute() throws Exception {
    
    
        UserServiceImpl userService=new UserServiceImpl();
        if(userService.add(getId(),getUserName(),getPassword())){
    
    
            message="添加成功";
            return SUCCESS;

        }else{
    
    
            message="添加失败";
            return "success";
        }

    }
}


package com.Action;

import com.Dao.UserDaoImpl;
import com.Service.UserServiceImpl;
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ModelDriven;

public class LoginActionModel implements Action {
    
    
    private String userName;
    private String password;
    private String message;
    public String getMessage() {
    
    
        return message;
    }
    @Override
    public String execute() {
    
    
        try{
    
    
            UserServiceImpl userService=new UserServiceImpl();
            if(userService.login(Integer.valueOf(getUserName()),getPassword())){
    
    
                message="登陆成功";
                return "success";
            }else{
    
    
                message="登陆失败";
                return "success";
            }
        }catch (Exception e){
    
    
            message="您未注册";
            return "success";
        }
    }
    public String getUserName() {
    
    
        return userName;
    }
    public void setUserName(String userName) {
    
    
        this.userName = userName;
    }
    public String getPassword() {
    
    
        return password;
    }
    public void setPassword(String password) {
    
    
        this.password = password;
    }
}


web界面

<%@ taglib prefix="S" uri="/struts-tags" %>
<%--
  Created by IntelliJ IDEA.
  User: gao
  Date: 2020/4/10
  Time: 17:47
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
  <title>login</title>
</head>
<body>
<S:form action="loginActionModel">
  <S:textfield name="userName" label="Username"></S:textfield>
  <S:password name="password" label="Password"></S:password>
  <S:submit></S:submit>
</S:form>
<S:a href="adduser.jsp">注册</S:a>

</body>
</html>


<%@ taglib prefix="S" uri="/struts-tags" %>
<%--
  Created by IntelliJ IDEA.
  User: gao
  Date: 2020/4/10
  Time: 19:53
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
<S:form action="adduser">
    <S:textfield name="id" label="id"></S:textfield>
    <S:textfield name="userName" label="Username"></S:textfield>
    <S:password name="password" label="Password"></S:password>
    <S:submit></S:submit>
</S:form>
</body>
</html>


<%@ taglib prefix="S" uri="/struts-tags" %>
<%--
  Created by IntelliJ IDEA.
  User: gao
  Date: 2020/4/10
  Time: 17:54
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
${
    
    message}

</body>
</html>

运行结果

在这里插入图片描述
在这里插入图片描述

虽然运行成功了,但是,我们尚未用Spring将他们进行整合,请看下一篇!

猜你喜欢

转载自blog.csdn.net/qq_41827511/article/details/106041103