• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

New to servlets

 
Ranch Hand
Posts: 580
Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
public class HelloWorld extends HttpServlet {

public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {

res.setContentType("text/html");
PrintWriter out = res.getWriter();



}
}


What does those to highlighted line mean...
Please explain...
 
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok. So lets imagine your browser as a File. So what do you do to write a file? You get a writer. The same here. Here we tell the browser before hand that "Hey Browsie! I m going to write on you and if you were just wondering what I m going to write - Its text in html format. Treat them as the same." Makes sense?

[ November 07, 2008: Message edited by: rakesh sugirtharaj ]
[ November 07, 2008: Message edited by: rakesh sugirtharaj ]
 
James Tharakan
Ranch Hand
Posts: 580
Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Whio is tell to whom ???
Client to server
or
server to client???

If server is telling to client, then it creates a doubt in me, that is...
It is the client who resquested so client know what type of data is coming.
then why is server again telling the same thing??

SORRY if i sound stupid
 
rakesh sugirtharaj
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Whio is tell to whom ???
Client to server
or
server to client???


Ofcourse, the server to client. The problem is your opinion of client is human. Sure I know I m looking for a excel sheet. But does my 'browser' know?

SORRY if i sound stupid

You have no idea how stupid i was(and still am ) when i was a beginner! Just dont stop being curious because you think its stupid.
 
James Tharakan
Ranch Hand
Posts: 580
Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException


So what are the details does the object req send to the server???
 
rakesh sugirtharaj
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here you go - the API docs
 
Bartender
Posts: 2856
10
Firefox Browser Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

It is the client who resquested so client know what type of data is coming.
then why is server again telling the same thing??



Its not the case always. The client only sends requests for a resource and the server decides what to serve back.
For instance consider a online form filling/billing a application. The moment you fill in the details and click Submit, a PDF version of the completed form or a receipt is sent back to you.

The content type also needs to be set so that the browser knows what to do with the content. Browsers like Firefox can be customized to deal with particular content types like open the file with an associated application or save it ,etc.
Setting the content types helps the browser with this also.


It gets a writer to the output stream of the response object, using which data can be written to the response.

Hope this helps
[ November 07, 2008: Message edited by: Amit Ghorpade ]
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic