Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does ServletRequest have setAttribute, instead of ServletResponse?

Tags:

jsp

servlets

I don't understand why ServletRequest has a setAttribute method. Eg: if i have a jsp page containing 1 textbox and a submit button...

My objective is when i submit my name should be displayed in that textbox. Question here: whatever is displayed in that textbox is response from servlet right?

But in my assignment in servlet part: It was written request.setAttribute("name","abc");

at jsp side:
It was written: <input type="text" value = < %request.getAttribute("name")% > >

I know in javadocs they have setattribute inside request but why not under response?

like image 346
swapyonubuntu Avatar asked May 25 '13 07:05

swapyonubuntu


1 Answers

Request : From Client to Server

Response: From Server to Client

When your client sends your servlet request, you add object in request and later retrieves it in jsp.The request is passed from servlet to jsp.Your jsp retrieves the object,generates a HTML and sends it as response back to your browser.The same request sent by your client is passed from one servlet or jsp to another jsp or servlet and then these are compiled to generate HTML format and sent to browser as response from server.Setting object in response doesnot make sense because browser just displays HTML.

like image 64
ntstha Avatar answered Sep 20 '22 05:09

ntstha