实验一 用struts2开发一个加法器
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
实验一用struts2开发一个加法器
1.index.jsp
<%@ page language="java" import="java.util.*" contentType="text/html;Charset=utf-8" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %>
2.add_result.jsp
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %>
nun1=${param.num1}
nun2=${param.num2}
result=${sessionScope.result}
3.Calculator类
package org.bean;
public class Calculator {
public double add(double a,double b){
return a+b;
}
}
4.AddAction类
package org.action;
import org.bean.*;
import com.opensymphony.xwork2.ActionContext;
public class AddAction {
private double num1;
private double num2;
public double getNum1() {
return num1;
}
public void setNum1(double num1) {
this.num1 = num1;
}
public double getNum2() {
return num2;
}
public void setNum2(double num2) {
this.num2 = num2;
}
public String execute(){
Calculator biz=new Calculator();
double result=biz.add(num1, num2);
ActionContext.getContext().getSession().put("result",result);
return "cal";
}
}
5.struts.xml配置