Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

JSPExample:- Using standard actions and scripting

Tags: gtlt
STEP 1: Create a “dynamic web” project named “FirstBean”.

STEP 2: Create a new package named” com.examp” under Src or Source Folder.

STEP 3: Create a new html file named “SampleHtml.html” under WebContent folder.

< html >
< head >
< title>Sample< /title >
< /head >

< body >
< form action="TestBean.jsp" >
Name: < input type="text" name="Username" >
ID#: < input type="text" name="UserID" >
<  input type="submit"  >
< /form >
< /body >
< /html >

STEP 4: Create a new java class named “Person.java” under Src folder.

package com.examp;
public abstract class Person {
private String name;
public void setName(String name) {
this.name=name;
}
public String getName() {
return name;
}
}

STEP 5: Create a new java class named “Employee.java” under Src folder

package com.examp;
public class Employee extends Person {
private int empID;
public void setEmpID(int empID) {
this.empID = empID;
}
public int getEmpID() {
return empID;
} }

STEP 6: Create a new JSP file named “TestBean.jsp” under WebContent folder

We can do it with a combination of standard actions and scripting
< body >
< jsp:useBean id="person" type="com.examp.Employee" class="com.examp.Employee"/ >
< % person.setName(request.getParameter("Username ")); % >
< % person.setEmpID(Integer.parseInt(request.getParameter("UserID "))); % >

Person:
< jsp:getProperty name="person" property="name" / >
ID is :
< jsp:getProperty name="person" property="empID" / >
< /body >
Or
We can even do it with scripting INSIDE a standard action:

< body >
< jsp:useBean id="person" type="com.examp.Employee" class="com.examp.Employee" >
< % person.setEmpID(Integer.parseInt(request.getParameter("UserID"))); % >
< jsp:setProperty name="person" property="name" value="" / >
< /jsp:useBean >

< jsp:getProperty name="person" property="name" / >
< jsp:getProperty name="person" property="empID" / >
< /body >

STEP7: Include below code in a Xml file “web.xml” under WEB-INF folder

< welcome-file-list >
< welcome-file >SampleHtml.html< /welcome-file >
< welcome-file >TestBean.jsp< /welcome-file >
< /welcome-file-list >

STEP 8 Export the project” FirstBean” into a war file named ” FirstBean.war” and place it in the deploy folder of JBOSS server.

STEP 9:To see the output use this url ” http://localhost:8080/ FirstBean / SampleHtml.html ”where FirstBean is the .war file name and SampleHtml.html is specified in the of web.xmlfile.

Step 10: Sample output is
Person is: Ammu ID is : 1


This post first appeared on Every Day Of Your Life Is A Page Of Your History, please read the originial post: here

Share the post

JSPExample:- Using standard actions and scripting

×

Subscribe to Every Day Of Your Life Is A Page Of Your History

Get updates delivered right to your inbox!

Thank you for your subscription

×