转换为 JSTL(特别是调用方法)
我正在采用完整的 JSTL 方式,并且我遇到了以下 scriplet 的问题,我已经将变量显示和条件转换为表达式语言(EL),但我不太确定如何通过方法调用来做到这一点:这是我的 JSP 代码,它位于 html 标记之前: <代码> UserDTO user = (UserDTO) session.getAttribute("用户");
OrderDAO lnkOrder = new OrderDAO();
OrderDTO order = new OrderDTO();
CoverDAO lnkCover = new CoverDAO();
CoverDTO cover = new CoverDTO();
UpgradesDAO lnkUpgrades = new UpgradesDAO();
UpgradesDTO upgrades = new UpgradesDTO();
OrderAccessorieDAO lnkOrderAcc = new OrderAccessorieDAO();
List<OrderAccessorieDTO> orderAccessories = new ArrayList<OrderAccessorieDTO>();
GroupColorsDAO lnkColors = new GroupColorsDAO();
List<ColorDTO> ColorList = new ArrayList<ColorDTO>();
ColorList = lnkColors.getGroupColors(user.getGroup());
AccessoryDAO lnkAcc = new AccessoryDAO();
List<AccessoryDTO> groupAccessories = new ArrayList<AccessoryDTO>();
groupAccessories = lnkAcc.getGroupAccessories(user.getGroup());
ChangesDAO lnkChanges = new ChangesDAO();
List<ChangeDTO> orderChanges = new ArrayList<ChangeDTO>();
String CurrentOrder = request.getParameter("CurrentOrder");
if (lnkOrder.exists(CurrentOrder)) {
order = lnkOrder.find(CurrentOrder);
cover = lnkCover.find(order.getReferenceNumber());
upgrades = lnkUpgrades.find(order.getReferenceNumber());
orderAccessories = lnkOrderAcc.getOrderAccessories(order.getReferenceNumber());
orderChanges = lnkChanges.getOrderChanges(order.getReferenceNumber());
}
正如您所看到的,它几乎是 DAO 和 DTO 对象,我知道它可以使用静态方法并制作自定义标记库来完成,但这意味着为每个方法调用编写代码,还有其他方法吗?接受建议。
VIEW
(HTML 标记)的简要描述,它显示给定订单的详细信息,订单名称是从 get
请求中提取的。
另外我还有另一个小问题,假设我将所有内容移植到 JSTL,我是否必须导入相应的 myDTO 和 myDAO 包才能访问每个 DTO 的 getter 和 setter?
问候特里斯蒂安。
I'm in the process of going the full JSTL way, and I've got an issue with the following scriplet, I have already transformed the variable displaying and conditions to the expression language (EL) but I'm not so sure of how to do it with method calling : here's my JSP code its positioned before the html markup:
UserDTO user = (UserDTO) session.getAttribute("user");
OrderDAO lnkOrder = new OrderDAO();
OrderDTO order = new OrderDTO();
CoverDAO lnkCover = new CoverDAO();
CoverDTO cover = new CoverDTO();
UpgradesDAO lnkUpgrades = new UpgradesDAO();
UpgradesDTO upgrades = new UpgradesDTO();
OrderAccessorieDAO lnkOrderAcc = new OrderAccessorieDAO();
List<OrderAccessorieDTO> orderAccessories = new ArrayList<OrderAccessorieDTO>();
GroupColorsDAO lnkColors = new GroupColorsDAO();
List<ColorDTO> ColorList = new ArrayList<ColorDTO>();
ColorList = lnkColors.getGroupColors(user.getGroup());
AccessoryDAO lnkAcc = new AccessoryDAO();
List<AccessoryDTO> groupAccessories = new ArrayList<AccessoryDTO>();
groupAccessories = lnkAcc.getGroupAccessories(user.getGroup());
ChangesDAO lnkChanges = new ChangesDAO();
List<ChangeDTO> orderChanges = new ArrayList<ChangeDTO>();
String CurrentOrder = request.getParameter("CurrentOrder");
if (lnkOrder.exists(CurrentOrder)) {
order = lnkOrder.find(CurrentOrder);
cover = lnkCover.find(order.getReferenceNumber());
upgrades = lnkUpgrades.find(order.getReferenceNumber());
orderAccessories = lnkOrderAcc.getOrderAccessories(order.getReferenceNumber());
orderChanges = lnkChanges.getOrderChanges(order.getReferenceNumber());
}
As yo can see it's pretty much DAO and DTO objects, I know that it can be done using static methods and making custom taglibs but that would mean writing a code for each method call, any other approach?, suggestions accepted. A brief description of the VIEW
(HTML markup) it displays the details of a given order, the order name is extracted from a get
request.
Also I have another small question, suppose I port everything to JSTL, would I have to import the corresponding myDTO
and myDAO
packages to access its getters and setters for each DTO?
Regards Tristian.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果视图和逻辑之间没有完全分离,“JSTL 方式”就没有意义,如 模型 2 方法。
在模型 2 方法中,您将此代码移至充当 JSTL 页面控制器的 servlet,并且仅使用 JSP 进行视图标记。否则,使用 JSTL 来强制逻辑和视图之间的分离是没有意义的。
"JSTL way" doesn't make sense without full separation between view and logic, as in Model 2 approach.
In Model 2 approach you move this code to the servlet that acts as a controller for your JSTL page, and only use JSP for view markup. Otherwise using JSTL to enforce separation between logic and view with JSTL would be meaningless.
我知道的唯一解决办法(肮脏的)是将这些方法公开为假地图,即有一个具有像“Object getSomething(Object o)”这样的签名的方法。通过这种方式,您可以传递一个参数,并且它可以绕过强加的规则。丑陋但它有效。
不过同意 axtavt
The only work around (dirty) that I know is to expose the methods as a fake map, that is have a method that has a sig like "Object getSomething(Object o)". In this way you can pass an argument, and it gets around the imposed rules. Fugly but it works.
Agree with axtavt though