struts

$null check in velocity

[亡魂溺海] 提交于 2019-11-29 02:48:46
I came to know about null check using $null in velocity 1.6 through a resource updated by you. Resource: Reading model objects mapped in Velocity Templates But I am facing so many challenges that there is no $null for null check in velocity as there is no documentation provided about this. Please provide me with documentation stating $null as valid for null check in velocity. Thanks in Advance lucky To check if a variable is not null simply use #if ($variable) #if ($variable) ... do stuff here if the variable is not null #end If you need to do stuff if the variable is null simply negate the

How to get the original request url from a servlet/jsp after multiple servlet forwards

放肆的年华 提交于 2019-11-29 01:38:14
问题 I am working on a cruise booking app using struts/tiles that uses multiple internal servlet/jsp forwards to reach the right jsp for display. But, once you reach the final jsp that is used to render the page, the ${pageContext.request.requestURL} call in that jsp returns the path of this jsp. For example Original request: /booking/getCruiseDetails gets forwarded to: /booking/validateCruiseDeteails.jsp gets forwarded to: /booking/validateUser.jsp finally gets forwarded to: /booking

Get current filename in JSP

随声附和 提交于 2019-11-29 00:58:01
问题 Is there a way to get which JSP is currently rendered, with JSTL or Struts (or without)? like _ _ file _ _ in Python and PHP? 回答1: Well ... yes ... in a way String __jspName = this.getClass().getSimpleName().replaceAll("_", "."); I'm using a JSP called pre.jsp for that which I include at the top of each JSP in my webapp: <%@page import="org.apache.log4j.Logger"%> <% String __jspName = this.getClass().getSimpleName().replaceAll("_", "."); Logger log = Logger.getLogger(this.getClass().getName()

Spring集成 Struts2

邮差的信 提交于 2019-11-29 00:45:07
Spring如何整合struts2? 1) 整合目标? 使IOC容器来管理Struts2的Action! 2) 如何进行整合? ① 正常加入Struts2 ② 在Spring的IOC容器中配置Struts2的Action 特别注意:在IOC容器中配置Struts2的Action时,需要配置scope属性,且必须指定为prototype! <bean id="personAction" class="com.lty.spring.struts2.action.PersonAction" scope="prototype"> <property name="personService" ref="personService"></property> </bean> ③ 配置Struts2的配置文件: action节点的class属性需要指向IOC容器中该bean的id <action name="person-save" class="personAction"> <result>/success.jsp</result> </action> ④ 加入struts2-spring-plugin-2.3.15.3.jar 3)整合原理 通过添加struts2-spring-plugin-2.3.15.3.jar以后,Struts2会先从IOC容器中获取Action的实例 if

Can I propagate struts2 ActionErrors between different action classes?

て烟熏妆下的殇ゞ 提交于 2019-11-28 23:40:03
If I have an action where the result is a redirectAction to another action in a different class, is it possible to get validation errors to display in the resulting action? E.g. in the following example, if a user executes actionA (which has no views associated with it), and there are errors, is there any way to display those errors in the actionB result (foo.jsp)? Or am I going about this in completely the wrong way? <package name="a" extends="struts-default" namespace="/a"> <action name="actionA" class="actionAClass"> <result name="input" type="redirectAction"> <param name="actionName"

EntityManager ThreadLocal pattern with JPA in JSE

纵然是瞬间 提交于 2019-11-28 21:32:49
I'm developing a simple "Book Store" project using Struts 1.3 + JPA (with Hibernate as persistence provider). I cannot switch to Spring or any other more sophisticated development environment (e.g., Jboss) and I cannot use any Hibernate-specific technique (e.g., Session class). Given the fact that I'm in a JSE Environment, I need to explicitly manage the whole EntityManager's lifecycle. The Book entity is defined as follows: @Entity public class Book { @Id private String isbn; private String title; private Date publishDate; // Getters and Setters } I defined three Action classes, which are

Why use 'redirect=true' in struts 1.* forward?

元气小坏坏 提交于 2019-11-28 17:31:44
问题 I've been having some problems with ActionMessages created during execution of an action which didn't display, and I found out that my problems were due to my forwards having redirect=true in struts-config.xml. Since the default behavior is redirect=false , I've been thinking about which benefits can one have using redirect=true and I couldn't find any answer. Does anyone know when and why redirect=true should be used in action forwards? 回答1: it prevents the 'double submit problem' Never show

How to pass a parameter in URL on a form submit in Struts2

萝らか妹 提交于 2019-11-28 13:57:48
I am doing a project in Struts2 where I need of setting a parameter in URL like user parameter in below link. I want this parameter to be passed when I click a form submit button and not any links separately. I know how to do this with <s:url> but that way I need to create a link instead of form submit. Can someone please help me with a code sample how to do this? I know there's a way to do it with HTML or Struts1 but how to do it with Struts2? If there is a way to do this in struts.xml , please explain with an example. <form action="/example/xyz.action?user=george" method="POST"> try this: <s

Using ActionForward with dynamic params in Struts 2

主宰稳场 提交于 2019-11-28 12:39:52
While migrating the application from Struts 1 to Struts 2 In some of the places, the same action class has been used for different type of views, based on the request params. For Example: if the createType is 1 means need to append one param or if the createType is 2 means need to append some more extra params, like that I need to pass dynamic params to some other action using ActionForward . struts-config.xml <action path="/CommonAction" type="com.example.CommonAction" scope="request"> <forward name="viewAction" path = "/ViewAction.do"/> </action> Action Class public class CreateAction

how can i pass value from javascript to a java class in struts2?

心不动则不痛 提交于 2019-11-28 10:47:15
问题 function redirect(id){ alert(id); document.forms["AddToCart"].submit(); } This is my javascript. How can i pass the value of 'id' into AddToCart.java. I am using struts2 framework. 回答1: You can store the value in a hidden field inside your form and so when the form is submitted the value will be sent to Action. <form name="AddToCart" ... > ... <input type="hidden" id="myid"/> ..... </form> then function redirect(id){ document.getElementById('myid').value = id; document.forms["AddToCart"]