Search This Blog

Wednesday, 28 January 2015

Write a program for servelet that generate plain text



import java.io.* ;
import javax.servlet.* ;
import javax.servlet.http.* ;


public class HelloWorld extends HttpServlet
{
public void doGet( HttpServlet Request request req, HttpServlet Response response res)throws Servlet Exception, IOException
 {
res.setContenttype("Type/HTML");
PrintWriter Pw=res.getWriter();
pw.println("
<html>
<head>
<title> Hello servelet</title>
</head>
<body>
<h1> Hello There !!</h1>
</body>
</html>");
}
}





                               OUTPUT










Write a program to generate plain text in java beans



import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

@ManagedBean(name="user")
@SessionScoped
public class UserBean
{

     public String text = "This is Text!";
     public String htmlInput = "<input type='text' size='20' />";

     //getter and setter methods...
}




                            OUTPUT






Write a programto handle exception using try and catch block



class Ex
{  
public static void main(String args[])
{
 int a=5;
 int b=0;
try
{
int c=a/b;
System.out.println("result="+c);
}
catch(Exception e)
{
System.out.println(e);
}
System.out.println("program terminated");
}
}




                            OUTPUT