KickJava   Java API By Example, From Geeks To Geeks.

Java > Java SE, EE, ME > javax > servlet > ServletRequest

javax.servlet
Interface ServletRequest

All Known Subinterfaces:
HttpServletRequest
All Known Implementing Classes:
HttpServletRequestWrapper, ServletRequestWrapper
See Also:
Top Examples, Source Code

public Object getAttribute(String name)
See Also:
RequestDispatcher, setAttribute(java.lang.String, java.lang.Object)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[194]getRealPath of config file
By Anonymous on 2005/02/03 09:51:32  Rate
String path = getServletContext (  ) .getRealPath (  "struts-config.xml"  ) ; 
 System.out.println (   path  ) ; 
 File file = new File (  path  ) ; 
 return file.lastModified (  ) ; 
  
  
 //getAttribute


public Enumeration getAttributeNames()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public String getCharacterEncoding()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public int getContentLength()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public String getContentType()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public ServletInputStream getInputStream()
                                  throws IOException
See Also:
getReader(), IllegalStateException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[691]Echo upload Servlet
By Anonymous on 2004/11/09 14:28:47  Rate
public class EchoUploadServlet extends HttpServlet {  
   public void doPost (  HttpServletRequest request, 
     HttpServletResponse response  )  
   throws ServletException, IOException {  
     ServletOutputStream out = response.getOutputStream (  ) ; 
     BufferedInputStream in = 
         new BufferedInputStream ( request.getInputStream (  )  ) ; 
     out.println ( request.getHeader ( "content-type" )  ) ; 
     int c = -1; 
     while  (   ( c=in.read (  )  )   > = 0  ) out.write (  c  ) ; 
     out.close (  ) ; 
    }  
  } 


[1537]_
By meetsagar { at } sify { dot } com on 2005/09/15 02:25:13  Rate
BufferedReader br = new BufferedReader ( new InputStreamReader ( request.getInputStream (  )  )  ) ; 
      String nextLine = ""; 
      StringBuffer sb = new StringBuffer (  ) ; 
      while  (  ( nextLine = br.readLine (  )  )  != null )   {  
        sb.append ( nextLine ) ; 
               sb.append ( lineSep ) ; 
       }  
    fileContent= sb.toString (  ) ; 
     
    out.println ( fileContent ) ; 
  
  
  
 Why this code is not working . Anyone knows about this reply to me.


public String getLocalAddr()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public Locale getLocale()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public Enumeration getLocales()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public String getLocalName()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public int getLocalPort()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public String getParameter(String name)
See Also:
getParameterValues(java.lang.String), getReader(), getInputStream()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[143]Get request parameter
By Abc on 2005/06/21 08:55:20  Rate
request.getParameter ( Abc ) ;

[1948]Difference between Attribute and Parameter
By Anonymous on 2007/12/24 17:50:01  Rate
"Attributes" and "parameters" are not at all the same thing. Parameters are what are parsed out of the query string, and/or out of the request body in the case of a form POST. Attributes are Java objects attached to particular pages, requests, sessions, or applications and referenced by name. Parameters are passed from client to server in a request; they are text-only. Attributes live only inside the application server, but they can be literally any object. 
  
  
 If you added attributes to the request with request.setAttribute (  ) , 
 eg 
  
  
 Public class Test extends HttpServlet  {  
  
  
 public void doGet  ( HttpServletRequest request, HttpServletResponse response )  
 throws ServletException, IOException 
  {  
   int [  ]  myIntArray = new int [ 10 ] ; 
   for ( int i=0;i < 10;i++ )  
    {  
     myIntArray = i; 
    }  
     request.setAttribute ( "myArrayName",myArray ) ; 
    }  
  }  
  
  
  }  
  
  
 JSP: 
  < % myIntArray =  ( int [  ]  )  request.getAttribute ( "myArrayName" ) ; 
 % >  
  
  
  
 You need to retrieve them with request.getAttribute (  ) ? Do please recognize that since they are confined to the application server, attributes attached to requests are lost in the process of an HTTP redirect. If by "forward" you meant using a RequestDispatcher or jsp:forward action to deliver the request elsewhere in the same application server, then your attributes will survive the process.


public Map getParameterMap()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[1297]Can not access the request input stream until ...
By Anonymous on 2005/02/09 17:16:12  Rate
//You can not access the request's input stream until after you  
 //have called the getParameterMap. 
 Map map = request.getParameterMap (  ) ;  
 PushbackInputStream in = new PushbackInputStream ( request.getInputStream (  )  ) ;  
 


public Enumeration getParameterNames()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[281]Display all request parameters and values
By joe { at } xdobs { dot } com on 2003/06/24 22:18:32  Rate
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
   public void doGet ( HttpServletRequest request, HttpServletResponse response )  
       throws ServletException, IOException  
   // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
    {  
     String aKey = null; 
     String [  ]       val_arr = null; 
     String aVal = null; 
     PrintWriter out = response.getWriter (  ) ; 
     response.setContentType ( "text/plain" ) ; 
     Enumeration pNames = request.getParameterNames (  ) ; 
     while  ( pNames.hasMoreElements (  )  )   {  
       aKey =  ( String )  pNames.nextElement (  ) ; 
       val_arr =  ( String [  ]  )  request.getParameterValues ( aKey ) ; 
       int ndx = 0; 
       while  ( ndx  <  val_arr.length )  
        {  
          aVal = val_arr [ ndx ] ; 
          System.err.println ( "aKey=" + aKey + " aVal=" + aVal ) ; 
          out.println ( "aKey=" + aKey + " aVal=" + aVal ) ; 
          ndx++; 
        }   // end while ndx 
      }  // end while ( pNames )  
     out.close (  ) ;     
  
  
 // by joe@xdobs.com tested on jetty 
 


public String[] getParameterValues(String name)
See Also:
getParameter(java.lang.String)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public String getProtocol()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public BufferedReader getReader()
                         throws IOException
See Also:
getInputStream(), IllegalStateException, UnsupportedEncodingException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public String getRealPath(String path)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public String getRemoteAddr()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public String getRemoteHost()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public int getRemotePort()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public RequestDispatcher getRequestDispatcher(String path)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[255]Dispatcher servlet
By Anonymous on 2003/05/15 18:46:02  Rate
public class Dispatcher extends HttpServlet  {  
  
  
     public void doGet ( HttpServletRequest request, 
                     HttpServletResponse response )   {  
  
  
         request.setAttribute ( "selectedScreen", 
         request.getServletPath (  )  ) ; 
         RequestDispatcher dispatcher = request.getRequestDispatcher ( "/template.jsp" ) ; 
         if  ( dispatcher != null )  
             dispatcher.forward ( request, response ) ; 
      }  
  
  
     public void doPost ( HttpServletRequest request, 
     ... 
  } 


public String getScheme()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public String getServerName()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public int getServerPort()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public boolean isSecure()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void removeAttribute(String name)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void setAttribute(String name,
                         Object o)
See Also:
removeAttribute(java.lang.String), RequestDispatcher
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[538]Get and set session attribute
By William Taiwan on 2003/11/20 21:32:45  Rate
... 
 // set the key to 'helloKey' and value = 'hello' 
 request.getSession ( true ) .setAttribute ( "helloKey","hello" ) ;       
 // return hello 
 request.getSession ( true ) .getAttribute ( "helloKey" ) ;       
 


public void setCharacterEncoding(String env)
                          throws UnsupportedEncodingException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  

Popular Tags