- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
对于我的 IT 大学的一个项目,我必须在 Strut2 应用程序中创建排雷游戏。对于服务器端,我使用 Tomcat。
您可以看到目前游戏的样子:
当我点击一个框时,我们必须看到一个数字或一个地雷。为此,案例有两个参数(X 和 Y),用于更新单击框的状态。为了使一个框可点击,我使用代码:
<a href="
<s:url action='demineur' method="connexion">
<s:param name="x" value="#x.index"/>
<s:param name="y" value="#y.index"/>
</s:url>
">
当我们想玩这个游戏时,我们必须输入用户名:
当我们登录游戏时,我们有一个以玩家名称创建的 session ,并且在 session 中我们有游戏的保存。
当我们与游戏交互时,游戏的保存就会更新
使用老师提供的 API (ModeleDemineur:1.1) 创建地雷,并显示如下:
<table>
<s:iterator status="x" var="ligne" value="cases">
<tr>
<s:iterator status="y" var="case" value="ligne">
<td>
<s:if test="getCachee()">
<a href="
<s:url action='demineur' method="connexion">
<s:param name="x" value="#x.index"/>
<s:param name="y" value="#y.index"/>
</s:url>
">
<img src="${pageContext.request.contextPath}/img/cellCovered.png"/>
</a>
</s:if>
<s:else>
<s:if test="getValeur() == -1">
<img src="${pageContext.request.contextPath}/img/mineExploded.png"/>
</s:if>
<img src="${pageContext.request.contextPath}/img/box<s:property value='getValeur()'/>.png"/>
</s:else>
</td>
</s:iterator>
</tr>
</s:iterator>
</table>
public class ActionDemineur extends ActionSupport implements SessionAware {
String username;
GestionDemineur demineur;
Plateau plateau;
Case[][] cases;
String val;
String x,y;
private Map<String, Object> session;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public GestionDemineur getDemineur() {
return demineur;
}
public void setDemineur(GestionDemineur demineur) {
this.demineur = demineur;
}
public Plateau getPlateau() {
return plateau;
}
public void setPlateau(Plateau plateau) {
this.plateau = plateau;
}
public Case[][] getCases() {
return cases;
}
public void setCases(Case[][] cases) {
this.cases = cases;
}
public String getVal() {
return val;
}
public void setVal(String val) {
this.val = val;
}
public String getX() {
return x;
}
public void setX(String x) {
this.x = x;
}
public String getY() {
return y;
}
public void setY(String y) {
this.y = y;
}
@Override
public void setSession(Map<String, Object> map) {
this.session = map;
}
public Map<String, Object> getSession() {
return session;
}
public String connexion() throws ExceptionLoginDejaPris {
if(!session.containsKey("user"))
{
if(username != null)
{
session.put("user", username);
}
else {
return INPUT;
}
}
if(!session.containsKey("plateau")) {
System.err.println("plateau not found");
demineur = new GestionDemineur();
demineur.connexion(username);
plateau = demineur.getPlateau(username);
cases = plateau.getMonPlateau();
session.put("plateau", plateau);
session.put("user", username);
}
username = (String) session.get("user");
plateau = (Plateau) session.get("plateau");
cases = plateau.getMonPlateau();
System.err.println(plateau);
if(x != null && y != null)
{
System.err.println("x and y not null");
System.err.println(Integer.parseInt(x) + " -- " + Integer.parseInt(y));
try {
plateau.decouvrirCase(Integer.parseInt(x), Integer.parseInt(y));
} catch (BombeException e) {
session.remove("plateau", plateau);
session.remove("user", username);
return "perdu";
}
System.err.println(plateau.getMonPlateau()[Integer.parseInt(x)][Integer.parseInt(y)]);
}
return SUCCESS;
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
"http://struts.apache.org/dtds/struts-2.5.dtd">
<struts>
<constant name="struts.devMode" value="true" />
<constant name="struts.enable.DynamicMethodInvocation" value="false"/>
<package name="/" extends="struts-default">
[...]
<action name="demineur" class="struts.ActionDemineur" method="connexion">
<result name="input">/WEB-INF/pages/connexionDemineur.jsp</result>
<result name="success">/WEB-INF/pages/demineur.jsp</result>
<result name="perdu">/WEB-INF/pages/perduDemineur.jsp</result>
</action>
</package>
</struts>
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>fr.univ-orleans.ufrst.info.l3.pnt</groupId>
<artifactId>HelloStruts2</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-core</artifactId>
<version>2.5.22</version>
</dependency>
[...]
<dependency>
<groupId>fr.miage.orleans.tp</groupId>
<artifactId>ModeleDemineur</artifactId>
<version>1.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>13</source>
<target>13</target>
<encoding>UTF-8</encoding>
</configuration>
<version>3.8.1</version>
</plugin>
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.4.25.v20191220</version>
</plugin>
</plugins>
</build>
<properties>
<maven.compiler.source>13</maven.compiler.source>
<maven.compiler.target>13</maven.compiler.target>
</properties>
</project>
ERROR ParametersInterceptor Developer Notification (set struts.devMode to false to disable this message):
Unexpected Exception caught setting 'x' on 'class com.opensymphony.xwork2.ActionSupport: Error setting expression 'x' with value ['0', ]
ERROR ParametersInterceptor Developer Notification (set struts.devMode to false to disable this message):
Unexpected Exception caught setting 'y' on 'class com.opensymphony.xwork2.ActionSupport: Error setting expression 'y' with value ['4', ]
我尝试在 struts.xml 中添加行 xml <interceptor-ref name=params />
但他删除了 session 中包含游戏保存和当前用户名的数据。
感谢您今后的帮助
最佳答案
我找到了答案!
我添加了一个参数方法,但这是一个真正的错误!
<s:url var="demineurURL" action='demineur'>
<s:param name="x" value="#x.index"/>
<s:param name="y" value="#y.index"/>
</s:url>
<s:a href="%{demineurURL}">
<img src="${pageContext.request.contextPath}/img/cellCovered.png"/>
</s:a>
关于java - 当我点击 <s :url> with params I have a Unexpected exception in class ActionSupport in Struts2 时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60224394/
我经常看到这个,但我一直不明白。为什么这么多函数在函数定义中有这些嵌套的括号和奇怪的逗号? 有点像 function name(param, param param) 对我来说有意义,或者 funct
为什么参数输入有两种不同的格式?除了个人品味之外,还有其他好处吗? 例如,我正在使用它,因为那是我第一次阅读有关Powershell的文档时所看到的 function MyAwesomeFunctio
当我转到角色 Controller 时,显示操作,所有正常的 params[:id] 都是根据 REST 应该如何。 在显示 View 中,我渲染了部分。在该部分中,我有一个指向 vote_socio
我正在尝试在我的 Express 应用程序中使用 Sequelize 获取数据,并使用 MSSQL 获取数据库。这是我的代码: getInstitution: function (req, res)
从 ASP.NET 中的代码隐藏访问表单或查询字符串值时,使用的优缺点是什么,例如: // short way string p = Request["param"]; 代替: // long way
这个问题已经有答案了: 已关闭11 年前。 Possible Duplicate: What is it called when you use object… as a parameter? 我在
在代码示例中,我看到了以下代码: SomeClass.Columns(columns => { columns.Add() .Text("Product")
我是 PySpark 的初学者。我在 PySpark 中使用 FPgrowth 计算关联。我按照以下步骤操作。 数据示例 from pyspark.sql.session import SparkSe
我想记录一个类,我在 PyCharm 中看到当自动添加文档字符串时它会添加 :param param_name1: :param param_name2: 不过,我看到有人用 @param param
我正在为一个网站设计 Android 客户端。所以我必须实现很多不同的网络操作。例如用户授权或在服务器上搜索。为此,我必须向 REST Web 服务器发送带有一些参数和 URL 的 JSON 请求。因
我对 Jersey 和 Grizzly 有疑问。这个问题可能非常基本,但我正在努力解决它。我的想法是,我正在创建一个需要存储书籍的练习应用程序。一切似乎都很好,但并没有按预期进行。这是源代码: @Pa
假设我有一个带有虚方法的接口(interface),但参数之一是: virtual void Delete(ParentClass *parentClass) = 0; 如果我稍后在子类中实现它 vo
需要一些 Python 语法方面的帮助 伪代码 if param is not None in params, param replace('xx', 'x') 我走到这一步了: param.repl
我刚开始使用 JSDocs,找不到这个问题的答案。 假设我想写这个简单的函数: function hasQ(array, item) {return array.includes(item);} 对于
我对doInBackground(Params...params)中的参数语法不熟悉 这种东西叫什么,我该如何使用它? 最佳答案 正如 devA 和 VVV 所说,这就是所谓的“可变参数”。实际上,以
我很难在两个 perl 模块之间做出选择——Params::Validate 和 Params::Check。 我正在编写一个应该易于分发的 Mojolicious 应用程序。 一般来说,我的意思是在
这个问题已经有答案了: What does [param: NotNull] mean in C#? (2 个回答) 已关闭 7 年前。 我发现了以下属性声明。 [param: Marsha
我正在阅读有关 $params 的 CakePHP 手册,并且想知道每个参数的适当用法是什么?我知道返回的数组略有不同(“url”实际上有一个名为“url”的数组键,它返回 Controller /操
我见过处理 *param1 和 ¶m2 的 C 函数调用 func1(*param1); func2(¶m2); 我知道 * 和 & 必须与指针相关。那么这两种不同的方式有
特别是,为什么对 *param 这样的参数的更改不会传播回函数的调用者,但对 **param 这样的参数的更改却会传播回来? 最佳答案 在这两种情况下,更改都会被传播,但这取决于调用函数。 请参阅下面
我是一名优秀的程序员,十分优秀!