java ee 新手求救啊!!!!!!!!!!!!
为啥我配置完web.xml就报404错误,不配置就不报呢?但是不配置有实现不了功能?咋办啊?这是比着书超的,书上也配置了
这是代码:
struts:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<constant name="struts.devMode" value="false"/>
<package name="p2" extends="struts-default" >
<action name="add" class="com.haiersoft.ch05.action.AddAction" >
<result name="cal">/add_result.jsp</result>
</action>
</package>
</struts>
AddAction.java:
package com.haiersoft.ch05.action;
import com.haiersoft.ch05.biz.Calculator;
import com.opensymphony.xwork2.ActionContext;
public class AddAction {
private double num1;
private double num2;
public double getNum1(){
return num1;
}
public void steNum1(double num1){
this.num1 = num1;
}
public double getNum2(){
return num2;
}
public void steNum2(double num2){
this.num2 = num2;
}
/**
* 调用业务逻辑方法,实现业务,控制流程转向
*/
public String execute(){
//新建业务逻辑对象
Calculator biz = new Calculator();
//调用业务逻辑方法,获得返回值
double result = biz.add(num1, num2);
//将计算结果存入Session中
ActionContext.getContext().getSession().put("result", result);
return "cal";
}
}
Calculator.java:
package com.haiersoft.ch05.biz;
public class Calculator {
/**
* 实现加法算数
*/
public double add(double a,double b){
return a + b;
}
/**
* 实现算数减法
*/
public double subtract (double a,double b){
return a * b;
}
/**
* 实现算数乘法
*/
public double divide(double a, double b){
//注意:此处为未判断除数不能为零,即b!=0,页面输入的第二个数不可为0,否则报错
return a / b;