Skip to main content

Posts

Showing posts with the label struts2 example

Struts2 Video Tutorial Part2

Struts 2 Simple Example and Configuration

Struts2 - Textfield Tag (Form Tags)

In this section, we are going to describe the textfield tag. The textfield tag is a UI tag that is used to render an HTML input field of type text. Add the following code snippet into the struts.xml file. struts.xml <action name="submitTag">   <result>/pages/uiTags/submitTag.jsp</result> </action> Create a jsp using the tag <s:textfield >  that renders an HTML input field of type text. <s:textfield label="Employee Name" name="empname" size="15" maxlength="10" /> tag displays an HTML text field with label equal to Employee Name with length of 15 columns. textfieldTag.jsp <%@ taglib prefix="s" uri="/struts-tags" %> <html>   <head>   <title>Textfield Tag Example</title>   </head>   <body>   <h1><span style="background-color: #FFFFcc">Tex...

Struts2 - Submit Tag (Form Tags)

In this section, we are going to describe the submit tag . The submit tag is a UI tag that is used to render a submit button. The submit tag is used with the form tag to provide asynchronous form submissions. The submit can have three different types of rendering: • input: renders as html <input type="submit"...> • image: renders as html <input type="image"...> • button: renders as html <button type="submit"...> Add the following code snippet into the struts.xml file. struts.xml <action name="submitTag">   <result>/pages/uiTags/submitTag.jsp</result> </action> Create a jsp using the tag <s:submit> that renders a submit button. This tag contains various parameters: The value parameter presets the value of input element. In our 1st case we have set it to " Submit " The type parameter sets the type of submit to use. Valid values are input, button and image. In o...

Struts2 - Select Tag (Form Tags)

In this section, we are going to describe the select tag. The select tag is a UI tag that is used to render an HTML input tag of type select. Add the following code snippet into the struts.xml file. struts.xml <action name="selectTag" class="net.struts2.weekDay">    <result>/pages/uiTags/selectTag.jsp</result> </action> Create an action class with a list populated with various items as shown below: weekDay.java package net.struts2; import com.opensymphony.xwork2.ActionSupport; import java.util.*; public class weekDay extends ActionSupport{      private List day;   public String execute()throws Exception{   day = new ArrayList();   day.add("Sunday");   day.add("Monday");   day.add("Tuesday");   day.add("Wednesday");   day.add("Thursday");   day.add("Friday")...

Struts2 - Password Tag (Form Tags)

In this section, we are going to describe the password tag. The password tag is a UI tag that renders an HTML input tag of type password. Add the following code snippet into the struts.xml file. struts.xml <action name="passwordTag"> <result>/pages/uiTags/passwordTag.jsp</result> </action> Create a jsp using the tag <s:password> . It renders an HTML input tag of type password. passwordTag.jsp <%@ taglib prefix="s" uri="/struts-tags" %> <html>   <head>   <title>Password Tag Example!</title>    </head>   <body>   <h1><span style="background-color: #FFFFcc">Password Tag Example! </span></h1>  <s:form>  <s:password label="Enter Password" name="password" size="10" maxlength="8" />   </s:form>   ...

Datetimepicker Tag Example

In this section, we are going to describe the datetimepicker tag. The datetimepicker tag is a UI tag that is used to render a date/time picker in a dropdown container. A stand-alone DateTimePicker widget that makes it easy to select a date/time or increment by week, month, and/or year. It is possible to customize the user-visible formatting with either the 'formatLength' (long, short, medium or full) or 'displayFormat' attributes. By default current locale will be used. Add the following code snippet into the struts.xml file. struts.xml <action name="datetimepickerTag" class="net.struts2.includeTag">    <result>/pages/uiTags/datetimepickerTag.jsp</result> </action> Create an action class as shown: includeTag.java package net.struts2; import com.opensymphony.xwork2.ActionSupport; import java.util.*; public class includeTag extends ActionSupport {   private Date m...

Create Struts2 project Using NetBeans

If you decide to start learning and using struts2, probably one of the first things you think about is which IDE to use, and what you need in order to create and run a Struts2 project... If you search the web , you'll find many tutorials on how to create a struts2 project, and start developing. This is what I did when I was starting, and soon find out that nothing I found on the web worked for me in proper manner... So, I decided to create a small tutorial on how to create an empty struts2 project , in order to help others, and save their time. Not to teach you Struts2, but to help you create a working Struts2 project! Ok, I will use NetBeans 6.5, and a Tomcat 6 that comes with it... First of all, go to http://struts.apache.org/2.x/index.html and download the latest version of Struts2. I downloaded struts-2.1.6-all.zip You won't be needing all the libraries in it. Just 6 of them. Because of this, you can download essential dependencies only. When you download one...

Create Struts2 Project Using MyEclipse

Create a struts project Create a new struts project with File > New > Project or use the shortcut Strg + n. Select the Wizard in J2EE Web Project Create a nice name for your project After creating the project , your Package Explorer looks like the picture below. For now your project is a normal J2EE project , so we need to add the struts capabilityies. Right click on the project and add the capabilityies for struts with Add Struts Capabilityies. Change the properties Base package for new classes and Default application resource Create a default welcome page Ok, now we want to create a default page. Right click (yes again) on the Folder WebRoot in the Project and choose New > JSP. Set the name to index.jsp and choose on template to use > Standard JSP using Struts 1.1 MyEcplise will use the template to create the JSP File. You will find the file index.jsp in the folder WebRoot of the project . On the top of the file you will find the struts tag l...