Wednesday, March 19, 2008

Dealing with a request

sample servlet that have written using netbeans.i have use only the doPost method.normally in netbeans they forward the request to the processRequest() method in the servlet.so these things can be done in that method olso.no difference.

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


public class NewServlet extends HttpServlet {

protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
//to get a parameter
String s= request.getParameter("what ever parameter sent from the previouse page");
//to get multiple parameters
String []s1= request.getParameterValues("para name");
//geting a header
String header= request.getHeader("name");
//get cookie info
Cookie []c= request.getCookies();
//to get session information
HttpSession session= request.getSession();
//to get clients port
getRemotePort();


}

//have to implement a method to get clients port
private void getRemotePort() {
throw new UnsupportedOperationException("Not yet implemented");
}

}

No comments: