RECENT POSTS
How to Override Default Theme in Struts 2 ?
Struts 2 have theme generation functionality due to which it automatically generates Table based HTML code for its tags. This is due the default theme (x_html) ** UPDATE: Struts 2 Complete tutorial now available here. Other themes are simple css_xhtml ajax You can change this theme setting to any other theme on tag level, page level or application level as shown below. 1. Tag Level <s:submit name="clear" action="ClearFormAction" value="Clear" theme="simple"...
read moreGet bytearray from pdf URL in java
Below code converts pdf from URL to byteArray It need common-httpClient.jar from apache HttpComponents . Download link – http://hc.apache.org/downloads.cgi String url= "http://gradcollege.okstate.edu/sites/default/files/PDF_linking.pdf"; byte[] byteArray = null; HttpClient httpClient =null; { try { httpClient =new httpClient(); httpGetmethod =new GetMethod(url); httpGetmethod.setFollowRedirects(true); byteArray = httpGetmethod.getResponseBody(); } catch (Exception...
read moreChanging default style of s:actionerror / s:actionmessage tag
In struts 2 when you use <s:actionerror /> tag, it displays the errors with bullets, On viewing the page source of the jsp page, we can see that error message is displayed using <ul> <li>error 1</li> <li>error 2</li> </ul> But suppose if our requirement is to display the error message without bullet in the action errors or action messages ** UPDATE: Struts 2 Complete tutorial now available here. There are 2 ways to solve this problem 1. Customized the...
read moreHow to get checkbox values from displaytag using struts2
Consider a scenario, such that we have a list of items and each item can be selected by checking its checkbox. Then a submit button is clicked after selecting all necessary checkboxes. So now, in our Action class, we could get the values of checkboxes which had been selected, by which we can implement delete functionality. ** UPDATE: Struts 2 Complete tutorial now available here. The following snippet of code is used to retrieve the value from a checkbox used inside displaytag. <display:table...
read moreStruts 2 tag not working in Display tag – Solution
Consider a scenario, such that you want to display a value of a column based on certain condition. For example: if a student’s marks is greater than 50 display as ‘pass’, if its less than 50 then display as ‘fail’. For this scenario, in a display tag, most of us result in the following code snippet. <display:table name="ranklist" id="row" pagesize="10" requestURI="rankAction" > <s:if test="%{mark >...
read moreConcept of Servlets Vs Concept of Struts 2
In this article we will discuss about the conceptual difference between Servlets and Struts 2 ** UPDATE: Struts 2 Complete tutorial now available here. In case of Servlet when we have N number of request then only one object is created out of which N number of Threads are created , in which a request object is created. So the objects inside the thread are safe and not shared with other thread objects. But suppose if the Servlet has Member variable, then those variable are not thread safe, as they are shared between...
read moreAjax implementation in Struts 2 without jQuery plugin
Zip file – AjaxInStruts2.zip AJAX is a technique for creating better, faster, and more interactive web applications. With AJAX, your JavaScript can communicate directly with the server, using the JavaScript XMLHttpRequest object. With this object, your JavaScript can transfer data with a web server, without reloading the page. This post elaborates on how to implement Ajax in Struts 2 application. ** UPDATE: Struts 2 Complete tutorial now available here. Action...
read moreHow to Call Struts2 action from java script
Action Class package com.simplecode.action; import com.opensymphony.xwork2.ActionSupport; public class MyAction extends ActionSupport { public String trueCall() { return SUCCESS; } public String falseCall() { return SUCCESS; } } ** UPDATE: Struts 2 Complete tutorial now available here. Jsp Pages File : confirmBox.jsp <%@taglib prefix="s" uri="/struts-tags"%> <html> <head> <title>Calling Action from java...
read moreDynamically add, remove list of objects from jsp Using Struts2
In this article we shall learn on how to dynamically add, remove list of objects from jsp Using Struts2. File : User.java (Model Class) package com.simplecode.action; import java.util.Collection; public class User { int regNo; String name; Collection<Address> addresses; public Collection<Address> getAddresses() { return addresses; } public void setAddresses(Collection<Address> addresses) { this.addresses = addresses; } public int getRegNo() { return...
read moreSolution for “Could not create the Java Virtual Machine” issue
If you get the below error message while executing java program Error:Could not create the Java Virtual Machine. Error:A fatal exception has occurres.Program will exit. To resolve this issue, following steps are needed to be followed (on Windows XP, Windows 7, Windows 8): Right Click on My Computer Icon and click on Properties Click on Advanced Systems Settings Then Environment Variables Under System Variables, click New In which give Variable Name as: _JAVA_OPTIONS Variable Value: -Xmx1024m Click...
read more