- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我用过ModelDriven
在我的Action
类,以前工作正常,现在停止工作了。
当我使用<s:debug>
时在我的 JSP 中使用 Struts 标签我发现以下结果:
Struts ValueStack
调试:
我正在 JSP 页面中访问值:
<s:property value="categoryName"/>
<s:property value="categoryId"/> // I typed here
工作正常,如果我访问它们:
<s:property value="category.categoryName"/>
<s:property value="category.categoryId"/>
我的问题是:
ModelDriven
,为什么?更新:
实际上我获得了 3 次属性,我忘了突出显示第 3 次。请看我的Action
类。
我尚未定义 Model
的单独属性我的操作中的类,用 1 突出显示,如何设置这些属性?
是任何东西吗,我在实现 ModelDriven
时做错了?
这是我的模型 CategoryAction
:
public class CategoryAction extends ActionSupport implements ModelDriven<Category>,
Preparable, SessionAware, ServletRequestAware, ServletContextAware {
private static final long serialVersionUID = 1L;
private Category category;
private Category [] categories;
private ServletContext servletContext;
private Map<String, Object> session;
private ServletRequest request;
@Override
public Category getModel() {
return this.category;
}
@Override
public void prepare() throws Exception {
this.category = new Category();
if( this.jmain == null )
this.jmain = new Jmain();
}
public void prepareCrudCategory() throws Exception {
this.categoryService = new CategoryService();
}
@Override
public String execute() throws Exception {
System.out.println("----------CategoryAction#execute()-----------");
if( this.category.getCategoryId() == 0)
this.category = this.jmain.getCategory( 1 ); //Get Main Category
else
this.category = this.jmain.getCategory( this.category.getCategoryId() );
System.out.println(this.category.toString());
return super.execute();
}
public Category getCategory() {
return category;
}
public void setCategory(Category category) {
this.category = category;
}
public Category[] getCategories() {
return categories;
}
public void setCategories(Category[] categories) {
this.categories = categories;
}
}
更新2:
这是我的 JSP 代码片段:
<form action="add-category" id="id-add-id-entry-form" name="addIdEntry" method="post">
<input type="hidden" id="opType" name="opType" value='<s:property value="opType"/>'>
<br /> <br />
<center>
<span id="id-message-span">
<s:if test="hasActionMessages()">
<h3 style="font-size: 22px; color: #FD0006; text-shadow: 2px 2px 3px rgba(255, 255, 255, 0.1); margin-left: 330px;">
<s:actionmessage />
</h3>
</s:if>
<s:if test="hasActionErrors()">
<h3 style="font-size: 16px; color: #FD0006; text-shadow: 2px 2px 3px rgba(255, 255, 255, 0.1); margin-left: 330px;">
<s:actionerror />
</h3>
</s:if>
</span>
<div id="id-id-entry-div" class="class-id-entry-div class-center">
<fieldset style="height: 100%; border-style: solid; border-width: 2px; border-color: #FEC458;"
>
<legend class="PageTitleUpperCase"> Add Category </legend>
<table cellspacing="5" cellpadding="2" border="0" width="65%" class="class-center">
<tr>
<td>
<span style="color: red">*</span>
<label class="Label_Green"> Patent Category Name :</label>
<s:if test=""></s:if>
</td>
<td>
<s:property value="opType"/><br>
<s:property value="categoryId"/>
<s:property value="categoryName"/>
<s:if test="%{opType == 0}">
<%-- <s:property value="categoryName"/> --%>
<input type="hidden" name="parentCategoryId" value='<s:property value="categoryId"/>' >
<label class="Label_Green">
<s:property value="categoryName"/>
</label>
</s:if>
<s:else>
<%-- <s:property value="parentCategoryName"/> --%>
<input type="hidden" name="parentCategoryId" value='<s:property value="parentCategoryId"/>' >
<label class="Label_Green">
<s:property value="parentCategoryName"/>
</label>
</s:else>
</td>
</tr>
<tr>
<td>
<span style="color: red">*</span>
<label class="Label_Green"> Category Name :</label>
<s:if test=""></s:if>
</td>
<td >
<input type="hidden" name="categoryId"
<s:if test="%{opType == 0}">value='0'</s:if>
<s:else>value='<s:property value="categoryId"/>'</s:else>
>
<input id="id-category-name-text" type="text" name="categoryName"
required="required" size="40" placeholder="Enter Category Name Here..."
<s:if test="%{opType == 1}">value='<s:property value="categoryName"/>'</s:if> >
</td>
</tr>
<tr>
<td></td>
<td align="left"><input type="submit" id="submit_img"
<s:if test="opType != 0"> value='Update'</s:if>
<s:else> value='Submit' </s:else> >
</td>
</tr>
</table>
</fieldset>
</div>
<s:debug/>
</center>
</form>
我如何得到ValueStack
使用调试标签的内容:
使用<s:debug/>
后,我得到了[debug]
单击链接时,将显示以下值:
<s:debug/>
对于列表类别页面,[debug]
单击链接后,将显示以下值:
最佳答案
modelDriven
interceptor将模型推送到 ValueStack
的 top
上,因此堆栈中同时拥有模型和操作。
ValueStack
是 Struts 框架实现的接口(interface),允许在处理请求时操作数据。它是如何工作的,您可以阅读here .
您可以在ValueStack
的不同级别上查找具有相同名称/键的属性,搜索顺序是从top
堆栈向下直到值已找到。
ModelDriven
操作简化了表单字段到模型对象的映射,但如果您需要对同一操作类执行多个模型,您可能会遇到困难。
您可能在验证、类型转换以及与拦截器一起使用的 Struts 框架的其他功能方面遇到困难。
如果您无法解决问题,不如从实现的接口(interface)中删除 ModelDriven
或重新配置拦截器堆栈以禁用 modelDriven
interceptor ,那么您就可以没有 ModelDriven
。
关于java - 为什么 ModelDriven 在 Struts 2 中停止工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41040018/
我正在尝试从 struts-config 调用使用 struts 1 中的操作转发属性,并且我想调用另一个操作,它位于另一个 struts.config 文件中。显然它不起作用! 我的代码是: In
我是 Struts 框架的菜鸟。我试图了解 Action 映射是如何工作的。假设我有一个发送 AJAX 请求的 JavaScript 文件: $("button").click(function(){
嗨,我愿意更新从数据库中获取并加载到 JSP 上的复选框的值。我正在创建员工资料。 Jsp 具有员工姓名、员工地址、员工技术技能等字段。 员工技能具有以下复选框以选择以下值 复选框 1:Java 复选
在上面的代码中,fo
如何找到正在使用的 Struts 版本 在 Web应用项目在 Eclipse 中? 我的 struts-config.xml 说 谢谢。 最佳答案 打开 struts jar 并在 META-INF
我一段时间以来一直试图找到这个问题的明确答案,但没有任何运气。我需要知道为什么Struts是紧耦合的? struts 的哪个组件使其紧密耦合。 最佳答案 这太棒了Mkyong article正如我们所
关闭。这个问题需要更多focused .它目前不接受答案。 想改进这个问题吗? 更新问题,使其只关注一个问题 editing this post . 关闭 5 年前。 Improve this qu
我只是尝试在带有 struts 提供的标签的 jsp 页面中包含一个文本框。但它表现得很典型。 在职的 不工作 所以,没有属性(property)'value' ,它不工作。 请帮帮我。 笔记: 使
我使用 eclipse 来实现原生 Struts 和 hybernate 支持应用程序在页面中显示一系列链接。我收到错误: javax.servlet.jsp.JspException: Cannot
我的 JSP 中有以下代码: .. .. .. .. 这在 struts-config.xml 中文件: 喜欢delete行动吧,我有edit和up
谁能解释一下 Struts 和 Tapestry 框架之间的区别或者它们之间的比较? 问候,马亨德拉·阿特尼亚孟买印度 最佳答案 此处更新了 Tapestry 教程:http://tapestry.a
我有一个在 weblogic 上运行的 j2ee 应用程序。我对我的多功能盒感到困惑。 我对 multibox 的了解是,选中的项目将在提交时作为字符串数组传递。 我不知道为什么在我的应用程序中,当我
我正在设计一个购物车项目,其中只有我的内容区域会发生变化,因此我使用 struts 磁贴对其进行了配置,并且一切正常,直到我在我的项目中遇到表单。每当我尝试使用图 block 显示表单(struts
我想删除在 Struts 1.3 显示标签中没有找到显示的消息,当没有从数据库中获取记录时。 有可能这样做吗...? 最佳答案 从我的角度来看,默认行为应该是在空数据源的情况下不显示任何消息。 emp
我在浏览器窗口中收到以下错误: org.apache.jasper.JasperException:javax.servlet.ServletException:javax.servlet.jsp.J
我是 Struts 的新手。我在 struts 中有一个现有的 java 项目。该项目有 struts.xml 和 .struts.mex 文件。我了解到 struts.xml 是 Action 类到
我遇到了问题。我一直在不同的论坛上寻找答案,但不幸的是我没有找到答案。我需要这个,因为我正在创建一个网页,您可以在其中更改语言,因此不能对其进行硬编码。我需要这样做: "> 所以我想将 html 标记
我正在使用 Struts 2.1.8.1。我想在我的 jsp 页面中使用 struts 提供的标签。例如 Transfer Program - Log
我创建了一个名为 RegesterAction 的新类,但我没有将此类保留在任何包中。如何在 struts.xml 中配置此类? 下面是 struts.xml 文件,但我无法理解属性值 "defaul
我正在开发一个支持 AJAX 的 JavaScript 前端,它可以调用用 Struts 编写的 Java 后端。我的问题是,当后端抛出异常时,客户端仍然会看到“200 OK”HTTP 响应代码,而不
我是一名优秀的程序员,十分优秀!