Apache Struts 2是一个基于servlet的可扩展框架,在其架构中实现了模型 - 视图 - 控制器(MVC)模式,用于创建企业级Java Web应用程序。
我正在学习 JavaBrains 教程,完成课程后,我运行了该应用程序,但出现了异常。 汤姆猫日志: 严重:启动过滤器 struts2 时出现异常 原因:无法加载
我有一个index.jsp,我从中调用一个操作类TestAction(单击超链接),该类有一个方法display(),用于从数据库加载组合框的值以及execute()方法,以
我已将 Struts 库更新至 2.2.1,并且必须进行一些小的调整,但测试越多,我发现的问题就越多。 我们通常使用: actionName = ActionContext.getContext().
我想将下拉列表的选定值保存到数据库中。 首先加载index.jsp。当我们单击index.jsp 的注册URL 时,我们可以从index.jsp 转到register.jsp。 struts.xml: <
如何在不使用复选框或单选按钮的情况下将表格的一行发送到 Struts 2 中的操作?
我有一个使用 标签显示的表格。表值包含在 ArrayList 中。我为列表的每一行都有一个编辑按钮。当用户单击编辑按钮时,内容...
在Struts 2中如何不使用<s:iterator>标签来检索HashSet的元素?
我正在使用 Struts 2。请帮助我理解如何使用 Struts 2 标签而不使用 Struts 标签来检索 HashSet 的元素。 struts.xml: 我正在使用 Struts 2。请帮助我理解如何使用 Struts 2 标签而不使用 Struts HashSet 标签来检索 <s:iterator> 的元素。 struts.xml: <struts> <constant name="struts.devMode" value="true" /> <package name="bundle" extends="struts-default" namespace="/"> <action name="fetchPage"> <interceptor-ref name="defaultStack" /> <result name="success">/jsp/page.jsp</result> </action> <action name="process" class="sample.action.Process" method="execute"> <interceptor-ref name="defaultStack" /> <result name="success">/jsp/result.jsp</result> </action> </package> </struts> Process.java(动作类): package sample.action; import java.util.HashSet; import java.util.Set; import sample.pojo.Customer; import com.opensymphony.xwork2.ActionSupport; public class Process extends ActionSupport { private Set<Customer> result = new HashSet<Customer>(); public String execute() { Customer cust1 = new Customer(); cust1.setAge(59); cust1.setName("Subramanian"); result.add(cust1); return SUCCESS; } public Set<Customer> getResult() { return result; } public void setResult(Set<Customer> result) { this.result = result; } } Cutomer.java - Pojo 类: package sample.pojo; public class Customer{ String name; int age; public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } } result.jsp - 查看: <!DOCTYPE html> <html> <head> <%@ taglib prefix="s" uri="/struts-tags"%> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"> <meta http-equiv="X-UA-Compatible" content="IE=8;" /> <title>Welcome Page</title> </head> <body> Welcome! <s:textfield id="custName" value="%{result[0].name}"/> </body> </html> 使用上面的代码,我无法读取HashSet页面中的result.jsp对象值。 您可以使用 () 符号代替 []。最后一个用于 List 和数组,或 Map。所以它不适用于Set。 <s:textfield id="custName" value="%{result(0).name}"/> 您应该将 id 属性添加到元素的类型中。 id 是映射集合的默认键。 public class Customer{ Integer id; String name; int age; //getter and setter } 与其他属性一起初始化 id 属性 Customer cust1 = new Customer(); cust1.setId(0); cust1.setAge(59); cust1.setName("Subramanian"); result.add(cust1); 您可以在通过集合的属性对集合进行索引中了解有关类型转换的更多信息。 还有 OGNL 开发指南,用于理解索引。 如何使用Struts2标签检索HashSet的元素而不使用<s:iterator>? 通过使用一些称为投影的 OGNL 魔法。 <s:textfield id="custName" value="%{result.{name}[0]}" /> result.{name} 将从 name 中的所有 result 值创建一个列表,并且 [0] 将检索该列表的第一个元素。 请注意,因为您使用的是 HashSet,所以不能保证迭代顺序。使用 LinkedHashSet 实现可预测的迭代顺序。 如果您想保留Set,您可以使用 <s:property value="%{result.iterator.next.name}"/> 或者 将 Set 更改为 List,List 有 get 方法,而 set 没有。 之后下面的两个都可以工作 <s:property value="%{result[0].name}"/> <s:property value="%{result.get(0).name}"/>
在 Struts 2 中使用 jQuery 的 Ajax 表单提交按钮
我有带有提交按钮的表单,当单击该按钮时,它会转发到下一页并从后端获取所有数据。但是,根据新的要求,页面需要保持不变...
在Struts 2中添加带有action属性的查询字符串参数
我正在附加带有操作属性的参数,但我在 Struts 2 页面上遇到异常。 PWC6212:需要等号 下面是我的带有附加参数的操作属性,wh...
java.lang.IllegalStateException:在 Struts 2 中已为此响应调用 getOutputStream()
这是我的代码,我收到以下异常 HTTP 状态 500 - 无法显示问题报告:java.lang.IllegalStateException:已为此调用 getOutputStream()
我在我的应用程序中使用 Struts 2。我有一个 MessageResources.properties,其中给出了所有键和值。该文件位于 ${tomcat_home}/properties/resources 位置。 我的问题...
如何一起使用Struts <s:iterator>和<s:if>标签?
我有名为 allAlbums 和 allPhotos 的对象列表。现在,我想显示每个相册中的所有照片,所以我使用了以下方法。 我的代码是: 我有名为 allAlbums 和 allPhotos 的对象列表。现在,我想显示每个相册中的所有照片,所以我使用了以下方法。 我的代码是: <s:iterator value="allAlbums"> <s:iterator value="allPhotos"> <s:if test="%{#allAlbums.albumid == #allPhotos.albumid}"> <s:property value="photourl"/> </s:if> </s:iterator> </s:iterator> 但是,它不起作用。有什么建议我做错了什么吗? 确保您的两个对象都有适当的 getter/setter,然后您可以使用 OGNL 提供的称为投影的功能。 <s:iterator value="allAlbums" var="album"> <s:iterator value="allPhotos.{? #this.albumid == #album.albumid}"> <s:property value="photourl"/> </s:iterator> </s:iterator> 您引用了错误的对象。为您要引用的记录定义一个 var 属性并引用它。 <s:iterator var="album" value="allAlbums"> <s:iterator var="photo" value="allPhotos"> <s:if test="#album.id == #photo.albumId"> <s:property value="photoUrl"/> </s:if> </s:iterator> </s:iterator>
Struts 2 中的 Java 应用程序可以管理多少个会话?
我正在开发事务管理应用程序,并且正在使用 Struts 2。 我在内部使用了一个会话来设置和获取值,例如 ActionContext.getContext().getSession().put("s...
如何使用 Struts 2 在 JSP 中获取操作 URL?
我有网址:http://demo.lendingclub.com/account/summary.action。 当访问这个URL时,它会首先进入authenticate拦截器,在拦截器类中,如果我使用: 字符串 uri = 请求。
为什么<s:property>标签无法访问Struts 2中的抽象父类成员
我在通过 Struts 访问属性时遇到问题。我想知道是否有人对 Struts 比较有经验,可以给我一些指导? Java 类的设置大致如下...
为什么在Struts 2中点击提交按钮时没有调用action?
当我单击提交按钮时,不会调用操作 reg1。 我的简单Struts应用程序如下: 网络.xml: 当我单击提交按钮时,不会调用操作 reg1。 我的简单Struts应用程序如下: web.xml: <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee z http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0"> <display-name>Struts2</display-name> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> <filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> </web-app> reg.jsp: <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Insert title here</title> </head> <body> <form action="reg1" > Username: <input type="text" name="username"> Password: <input type="text" name="password"> Mobile: <input type="text" name="mobile"> <input type="submit" > </form> </body> </html> 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> <package name="default" extends="struts-default" namespace="/"> <action name="reg1.action" class="bean.regbean"> <result name="success">/login.jsp</result> </action> </package> </struts> 该操作未被调用,因为它错误地映射到表单操作属性中的 url。使用此操作配置来映射操作名称,使用时不带 .action 后缀。 <action name="reg1" class="bean.regbean"> <result name="success">/login.jsp</result> </action> 另请注意,FilterDispatcher 在最新的 Struts2 版本中已被弃用。因此,您必须相应地升级和修改web.xml。 在 JSP 中,您可以使用 struts 标签将字段绑定到 bean 属性。
如何修复 SizeLimitExceededException:请求因大小 (337867) 超出配置的最大值 (200) 而被拒绝?
如何处理 Struts 2 中的自定义拦截器执行? org.apache.commons.fileupload.FileUploadBase$SizeLimitExceededException: 请求被拒绝,因为其大小 (337867) 超出了
当我在 Struts 2 中使用调度程序结果时,我没有收到操作错误。 在操作类中,以下代码用于添加错误消息。 添加操作错误(“错误”); 返回“失败&q...
我在Struts 2中创建了一个自定义拦截器MyInterceptor.java,它从index.jsp页面获取参数值用户名和密码,并将这些参数中的字符串转换为大写。
我需要导出Excel工作表,因此通过Ajax从对话框窗口调用操作类方法。我有 Excel 图标,当我单击该图标时,就会调用一个方法,并处理后端...
我需要导出Excel工作表,因此通过对话框窗口中的Ajax调用来调用操作类方法。我有 Excel 图标,当我单击该图标时,就会调用一个方法,并处理后端...