gpt4 book ai didi

jsp - Struts2 上的通配符映射

转载 作者:行者123 更新时间:2023-12-02 04:49:33 24 4
gpt4 key购买 nike

<分区>

我遵循了关于如何在 Struts2 中使用通配符技术的在线教程,但它并不像显示的那样工作。在执行命令时,它只调用 execute() 方法,从不调用任何其他方法。我不确定问题是什么,但任何帮助都会很棒。

下面是我的 Action 文件和将 Action 链接到 JSP 页面上的 JSP 调用的 struts 文件。

CalculatorAction.java

package com.simplecode.action;

import com.opensymphony.xwork2.ActionSupport;

public class CalculatorAction extends ActionSupport
{
private float number1;
private float number2;
private float result;
private String methodName;




public String add()
{
System.out.print("afsnjfbkjsdfhdskfhsdkjfhksdjfhkdsjfhksdjfhsdkjfhksjfhkjdsfhdsk");
result=number1+number2;
setMethodName("add Method");
return SUCCESS;
}

public String subtract()
{
result = number1 - number2;
setMethodName("subtract Method");
return SUCCESS;
}

public String multiply()
{
result = number1 * number2;
setMethodName("multiply Method");
return SUCCESS;
}

public String divide()
{
if(number2!=0)
result = number1/number2;
else if(number1!=0)
result = number2/number1;
else
result=0;

setMethodName("divide Method");
return SUCCESS;
}

public float getNumber1() {
return number1;
}

public void setNumber1(float number1) {
this.number1 = number1;
}

public float getNumber2() {
return number2;
}

public void setNumber2(float number2) {
this.number2 = number2;
}

public float getResult() {
return result;
}

public void setResult(float result) {
this.result = result;
}

public String getMethodName() {
return methodName;
}

public void setMethodName(String methodName) {
this.methodName = methodName;
}
}

struts.xml

<?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.enable.SlashesInActionNames" value="true"/>
<constant name="struts.mapper.alwaysSelectFullNamespace" value="false"/>
<constant name="struts.enable.DynamicMethodInvocation" value="false"/>
<constant name="struts.devMode" value="true"></constant>
<package name="default" extends="struts-default">
<action name="*Calculator" method ="{1}"
class="com.simplecode.action.CalculatorAction">
<result name="success">curd.jsp</result>
</action>
</package>

</struts>

curd.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@taglib uri="/struts-tags" prefix="s"%>
<html>
<head>
<title>Dispatch Action</title>
</head>
<body>
<s:form action="Calculator">
<table>
<tr><td><s:textfield name="number1" label="Number 1 " id="number1"/></td></tr>
<tr><td><s:textfield name="number2" label="Number 2 " id="number2"/></td></tr>
<tr><td><s:textfield name="result" label="Result " readonly="true"/></td></tr>
<tr><td><s:textfield name="methodName" label="Method involked " readonly="true" /></td></tr>
<tr>
<td><s:submit value="addCalculator" align="left" /></td>
<td><s:submit action="subtractCalculator" value="Subtract" align="left"/></td>
<td><s:submit action="divideCalculator" value="Divide" align="left"/></td>
<td><s:submit action="multiplyCalculator" value="Multiply" align="left"/></td>
<td><s:submit align="left"/></td>

</tr>
</table>
</s:form>
</body>
</html>

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com