Showing posts with label J2ee Tutorial 12 :- Jsp standard actions. Show all posts
Showing posts with label J2ee Tutorial 12 :- Jsp standard actions. Show all posts

Tuesday, 27 November 2012

J2ee Tutorial 12 :- Jsp standard actions

// Jsp standard actions  example

Step 1 :- Create a dynamic web project

Step 2 :- Create a html as given bellow which will be our first page to load

<html><head><title>Music CD</title></head>
<body>
<h2>Music CD Details</h2>
<p>Type in the details of a music CD below...<p>
<form action="musicCDsummary.jsp">
<br />Title: <input type="text" name="title" />
<br />Artist: <input type="text" name="artist" />
<br />Year of Release: <input type="text" name="year" />
<br />Favorite Track: <input type="text" name="track" />
<br /><input type="submit" value="Continue..." />
</form></body></html>

Step 3 :- Now create  musicCDsummary.jsp were we will be using jsp standard actions to store the data

<html><head><title>Music CD</title></head>
<body>
<h2>Music CD Summary</h2>
<jsp:useBean id="musicCD" class="web.prac.MusicCD" />
<jsp:setProperty name="musicCD" property="*" />//storring the data to bean
<jsp:setProperty name="musicCD" property="yearOfRelease" param="year" />//storring param
<jsp:setProperty name="musicCD" property="favoriteTrack" param="track" />
<p>These are the details you entered...</p>
<br />Title: <b><jsp:getProperty name="musicCD" property="title" /></b>
<br />Artist: <b><jsp:getProperty name="musicCD" property="artist" /></b>
<br />Year of Release: <b><jsp:getProperty name="musicCD" property="yearOfRelease" /></b>
<br />Favorite Track: <b><jsp:getProperty name="musicCD" property="favoriteTrack" /></b>
</body></html>


Step 4 :- Now create the MusicCD bean  should strictly follow javabean standards

package web.prac;

public class MusicCD {
    private String title;
    private String artist;
    private String favoriteTrack;
    private int yearOfRelease;
    public MusicCD() {
       super();
    }
   
    public String getArtist() {
        return artist;
    }
    public void setArtist(String artist) {
        this.artist = artist;
    }
    public String getFavoriteTrack() {
        return favoriteTrack;
    }
    public void setFavoriteTrack(String favoriteTrack) {
        this.favoriteTrack = favoriteTrack;
    }
    public String getTitle() {
        return title;
    }
    public void setTitle(String title) {
        this.title = title;
    }
    public int getYearOfRelease() {
        return yearOfRelease;
    }
    public void setYearOfRelease(int yearOfRelease) {
        this.yearOfRelease = yearOfRelease;
    }
}

Step 5 :- Clean build the project and run the html file

//output:-


After enterring the data click on continue the data will be stored to the usebean and the will also be displayed in the jsp



 

Custom single threaded java server

 package com.diffengine.csv; import java.io.*; import java.net.*; import java.util.Date; public class Server { public static void main(Str...