jsp:plugin action to include applet (Example – 2)

Example to include Applet in JSP

webapps/mca2015/applet/MyApplet.java

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
 
import javax.swing.JApplet;
import javax.swing.JLabel;
 
public class MyApplet extends JApplet {
     
    private JLabel label = new JLabel();
     
    public void init() {
        label.setHorizontalAlignment(JLabel.CENTER);
        label.setFont(new Font("Arial", Font.BOLD, 20));
        label.setForeground(Color.BLUE);
         
        setLayout(new BorderLayout());
        add(label, BorderLayout.CENTER);
    }
     
    public void start() {
        String firstName = getParameter("firstName");
        String lastName = getParameter("lastName");
        label.setText("Hello " + firstName + " " + lastName);
    }
}

webapps/mca2015/appletdemo.jsp

<jsp:plugin
type="applet"
code="MyApplet.class"
codebase="applet"
height="200"
width="200"
/>

jsp:plugin action to include applet (Example – 1)

Example to include Applet in JSP

webapps/mca2015/applet/MyApplet.java

import java.awt.*;
import java.applet.*;

public class MyApplet extends Applet
{
	public void paint(Graphics g)
	{
		g.drawString("MCA4B",100,100);
	}
}

webapps/mca2015/appletdemo.jsp

<jsp:plugin
type="applet"
code="MyApplet.class"
codebase="applet"
height="200"
width="200"
/>

jsp:param action demo (Example 2)

Passing parameters to included page using jsp:param action within jsp:include action

paramdemo.jsp

<html>
	<body>
		<jsp:include page="/WEB-INF/form.jsp">
			<jsp:param name="bg" value="YELLOW" />
		</jsp:include>
	</body>
</html>

/WEB-INF/form.jsp

<html>
	<body>
		<form>
			<input type="text" name="fg">
			<input type="text" name="bg">
			<input type="submit" value="submit">
			<%
				out.println (request.getParameter("fg"));
				out.println (request.getParameter("bg"));
			%>
		</form>
	</body>
</html>

include directive Example

Include Directive Example

/WEB-INF/header.jsp

<h2> ABCXYZ Co.</h2>
<%
	response.setContentType("application/ms-word");	
%>

/WEB-INF/footer.jsp

<i> Copyright ABC - 2015</i>
<%@ include file="/WEB-INF/header.jsp"%>
Course Information
<h3> MBA</h3>
<%
	out.print ("hello ...");
%>
<%@ include file="/WEB-INF/footer.jsp"%>