软件151  王帅

在搭好框架的前提下,首先编写action.java文件:

import com.opensymphony.xwork2.ActionSupport;

public class UserAction extends ActionSupport {

    private int name;
    private int password;
    private int n;
    public int getName() {
        return name;
    }

    public void setName(int name) {
        this.name = name;
    }

    public int getPassword() {
        return password;
    }

    public void setPassword(int
            password) {
        this.password = password;
    }
    

    public int getN() {
        return n;
    }

    public void setN(int n) {
        this.n = n;
    }
    public String login() {
    
        n=name+password;
            return "success";
        
    }
}
action.java

然后在编写简单的主界面login.jsp:

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>登录界面</title>
    </head>
    
    <body>
        <form action="login" method="post">
            加法运算:<input type="text" name="name" />
            +<input type="text" name="password" />
            
            <input type="submit" value="结果" />
        </form>
    </body>
</html>
login.jsp

最后在编写返回结果login_success.jsp:

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%-- <%@ taglib prefix="s" uri="/struts-tags" %> --%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>登录成功</title>
    </head>
    
    <body>
        
        结果: ${n}
    </body>
</html>
login_success.jsp

好了,一个简单的加法运算就完成了!

浏览器显示logi.jsp:

 

login_success.jsp:

posted on 2017-03-06 10:02  世.外.人  阅读(328)  评论(0编辑  收藏  举报