Friday, March 19, 2010

J2ee Technologies

Struts Application using NetBean IDE
Struts Framework using NetBean IDE

AIM:

Creating Login Function using NetBean IDE. If username is suresh and password is kumar,the success page will display. Otherwise failure page will display.

Requirement:

NetBean IDE

Download NetBean

Procedure:

Step 1:
Create Project (LoginPro)

Create Project. File—New Project—New Project window will opened. Select web in categories and select web Application in projects. Next—New web Application window will opened. Where we give Project Name like LoginPro—Next—Another New web Application window will opened. and select checkbox for struts and Finish.

Step 2:

Create Directory Structure


A).Right Click on web pages and New—Folder where you give folder name like jsp.

B).Right Click on Source packages and New –Folder where you give folder name like actionform.

C).Right Click on Source packages and New---Folder where you give folder name like actions.


Step 3:


Create ActionForm class


Right Click on actionforms folder which already we have created.New---Other---New File window will opened. Where we select struts in categories parts and select struts actionform bean in File types parts and give actionform name like loginform Finish.




Step 4:

Create Action class (Controller)

Right Click on actions folder and New---other---New File window will opened. Where we select struts in categories parts and select struts action in File types parts. Next and New struts action window will open. Where we give Class Name like loginaction and Action path and Next and Finish.

Step 5:

Create Success.jsp for success page.

Create Failure.jsp for failure page.


Success.jsp

*Html/*

*Head* *title* Success! Welcome *title* */head*

*body*
Success! You Welcome.
*/body*

*/html*



Failure.jsp

*Html/*

*Head* *title* Failure! Sorry *title* */head*

*body*
Sorry! Enter Correct Username and Password
*/body*

*/html*



Note:

Please put into starting tag and into ending tag .

Step 6:

Configure struts-config.xml file


Made some changes inside action-mapping tag.

…….
…….
* action-mappings*


* action
input="/jsp/loginform.jsp"
name="loginform"
path="/loginaction"
scope="session"
type="actions.loginaction" *

* forward name="success" path="/jsp/success.jsp" / *

* forward name="failure" path="/jsp/failure.jsp"/ *

* /action*

* action input="/" name="NewStrutsActionForm" path="/loginaction1" scope="session" type="actions.loginaction1"/*

* /action-mappings*

………
………


Please put into starting tag and into ending tag .



Step 7:

Create jsp file like loginform.jsp for getting Form Field.

* %@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" % *
* %@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %*
*%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %*

*html*
*head*

*title* JSP Page */title*

*/head*
*body*
*html:form method="post" action="/loginaction"*

Username *html:text property="name" /*


Password *html:password property="password" /*


*html:submit value="OK"/*

*/html:form*
*/body*
*/html*



Please put into starting tag and into ending tag .


Put action name in form tag is same as path attribute of the action tag in struts-config.xml file.



How To Run:

Right Click on loginform.jsp and Run File or Shift+F6
Sample Struts Framework
Struts Framework

Requirements: A). Eclipse 3.2 B). MyEclipse 5.5

Installation:

Step 1). Install Eclipse 3.2 like E:\eclipse3.2

Step 2). Install MyEclipse 5.5 in the same folder E:\eclipse3.2

Note : You Are Ready to run Struts Application

Aim: How To create struts Application-using Eclipse.

Problem: Create Login Page.

Step 1. Create Project.

Step 2: Include Struts capabilities like Right Click on Project and MyEclipse and add Struts capabilities.

Step 3: Create Folder

1. actionforms :Right Click on src Folder and new and Folder and type actionforms.
2. actions:Right Click on src and new and Folder and type actions.
3. resources: Right Click on src and new and Folder and type resources.
4. jsp:This Folder for to save jsp file. Right Click on webroot and new and Folder and type jsp.

Step 4: Create actionforms like


Step 5: Create actions like


Step 6: Create success.jsp and failure.jsp

Step 7: Configure struts-config.xml file under WEB-INF

Add name arrtibutes in the action tag that name is same as form-bean’s name(above displayed form-bean).

Add forward

Add forward


Step 8: Change path and action

Step 9: Run the Tomcat server

Step 10: Deploy the

Step 11: Open the Browser and entered http://localhost:8080/LoginPro/jsp/loginform.jsp