#9 Servlet and JSP Tutorial | sendRedirect | URL Rewriting
HTML-код
- Опубликовано: 11 окт 2024
- Complete Servlet and JSP playlist : goo.gl/pKFeSv
Editing Monitors :
amzn.to/2RfKWgL
amzn.to/2Q665JW
amzn.to/2OUP21a.
Check out our website: www.telusko.com
Follow Telusko on Twitter: / navinreddy20
Follow on Facebook:
Telusko : / teluskolearn. .
Navin Reddy : / navintelusko
Follow Navin Reddy on Instagram: / navinreddy20
Subscribe to our other channel:
Navin Reddy : www.youtube.co....
Telusko Hindi :
www.youtube.co....
Donation:
PayPal Id : navinreddy20
Patreon : navinreddy20
www.telusko.com...
The tutorials are great. This is my first tutorial series on the channel. Navin Sir is amazing at Java and on the concepts. Recommended to all Java lovers or better be learners.
I realize I am pretty off topic but do anybody know a good site to stream new tv shows online ?
@Dwayne Jayce Flixportal :D
@Jeremias Cristian thank you, I signed up and it seems like they got a lot of movies there :D Appreciate it!!
@Dwayne Jayce glad I could help :D
Great tutorial, We enjoyed it sir. God bless You
The session was great
this video was amazing sirrrr!!!!!!!!!!!!
hello sir, since we're modifying the url from res.sendRedirect("sq") to res.sendRedirect("sq?k="+k), how the compiler is looking this new url-pattern in web.xml? since we've defined url-parttern for only "sq" not "sq?k=".
good Q. if you don't understand ask me
even i want to know this.
but where is the answer?
Hello folks, our main route will be "sq" only. Whatever after "?" is considered as query. Get request parameters are passed that way.
But if "sq" ended with "/", then new sub route will start from there. For example "sq/abc" will not match with any current url-pattern.
Thank you so much Navin.
Thanks a lot. It really helped me to prepare for my practical examination
Hi Navin , thanks for your content. If i'm using doPost method instead of doGet it does not work. Could you may be shed some light on that
doPost uses secured base URL so if we use doPost then in its URL hides info of what we are sending and it don't display info of what we are sending so we can't this URLRewriting method for doPost but if we use doGet in its URL it won't hide info of what we are sending so it displays info of what we are sending so we can use URLRewriting method....
@@lasyagajavelli594 so we can't use dopost in the case urlRewriting
@@kreenu5035 no we can't use post method for url rewriting
Just superb
Thanku navin garu🙂
Great sir thanku so much
THANKYOUVERYMUCHHHHH!!!!!!!!!!!!!!!!!!!
Отличное видео Perfect
In web.xml we have mentioned sq in servlet-mapping how can it map the same after using sq?k= in send redirect.
we are using doGet method. That's y its working also we are using sendRedirect.
thanks a lot
Would changing the intro music be a good idea? Cuz it's like as if I'm about to watch a comedy film when I heard it, lol
Hi Navin, I believe there is one more concept called 'Hidden Form Field' in session management technique. we can send data from one servlet to another with this hidden field.
please tell us about it too
could you please explain it sir
Hi Navin, Firstly I would like to thank you for this wonderfull series.I have one doubt i.e. sendRequest can be use only with get method ?
These two looks like similar purpose. Are these function doing the same purpose or depending on a certain occasion?
very helpful video congratulations grom greece man
Thanks Sir😊
Great teaching sir. Thanks for ur videos.
I have a small doubt in this concept. Please clarify sir.
In the URL Rewriting, we actually changed the url pattern the client should call the sq servlet, but that same url pattern is not configured in web.xml.
Then, how do the server know to call the same sq servlet?
Thanks in advance.
changing URL pattern and adding parameters are different.
We have only added parameters not changed patterns.
What if we want to send the data using post method in sendredirect() ,would we able to do so?
I have tried bt it's not working may be some another method will work .do you know?how can we do that
Yes you have to call get method from post method and write all the code in get method just invoke it through post
But why response dispatcher is used instead of this redirect method? Which one is common to use? Or in what circumstances we should use either one? Any practical example(s)? Thanks.
ResponseDispatcher is to be used when the second servlet that is being called by the first servlet is part of the same website i.e. it belongs to the same domain. Here the second servlet may be responsible for some processing work and then returns the result. So in this case when the client sends a request to the servlet1, the result the client will see will be a response from servlet2 but in the url still servlet1's url pattern would be there.
So do we should use sendRedirect or Dispatcher ?
Thank you so much Sir :)
Thanks
can anyone help me ... after using setattribute in AddServlet i got an error coz it is saying that k is not an int type..convert into object..but after making it as object i get an error in ...int k = i + j;..
how to resolve it?
But what happens when we use doPost method and we can not see the values in the URL?
that's why we have 2 more methods
great
If we want to attach token or password in sendRedirect (so that user can give information to payment gateway), then we won't do it in URL. User will send POST request to payment gateway. How can we do that?
Did you get answer for this? Iam also looking for redirect for POST request
hai navin, can you explain
1) why to use req object while using RequestDispacher and
res object while using sendredirect in the same servlet(AddServlet)
2)Why U r using req object in sqservlet when ur sending res object from AddServlet
suraj chennoju req object for request dispatcher cause u r calling a servlet from a servlet while redirect u r calling a servlet from html page
1) It is so because, here, when the AddServlet wants to interact with another servlet then it uses the req object. E.g. Here, using the getRequestDispatcher() and the forward() methods the AddServlet is interacting with the SqServlet but when it wants to interact with the client (i.e. the index.html) then it uses the res object. E.g. Here, using the sendRedirect() method the AddServlet is sending its response to the client and telling the client to redirect the call to another servlet. You might also have noticed that when a servlet wants to send results to the client it uses the res object as in res.getWriter() statement.
2) Now, you know, using the method call res.sendRedirect() the AddServlet is not sending the res object to the SqServlet but it is sending its response to the client.
These were informal answers to your questions. I answered in the similar way you asked. Now, try to understand the exact technical reasons behind these:
The getRequestDispatcher() method is declared in the ServletRequest interface which is the superinterface of the HttpServletRequest interface i.e. the HttpServletRequest interface extends the ServletRequest interface where the getRequestDispatcher() method is declared, this is why the HttpServletRequest object req (in this case) is used to invoke the getRequestDispatcher() method. Now, the reason why the RequestDispatcher interface is used is simple and that is, because the getRequestDispatcher() method returns an object of this interface and this is the interface where the forward() method is declared.
I hope, you understood all.!!
Can we use both sendRedirect and req dispatcher together?
Thnx sir
when we change url from sq to "sq?k=" , doesn't the web.xml file plays a role in executing the url mapped in servlet mapping
Our main route will be "sq" only. Whatever after "?" is considered as query. Get request parameters are passed that way.
But if "sq" ended with "/", then new sub route will start from there. For example "sq/abc" will not match with any current url-pattern.
telusukunna sir
Hey Iam facing an error that is HTTP 500 -INTERNAL ERROR could you please tell me the solution
Hi, Im created by HTML file in one folder and another created by java file
how to linking to two file
dont we need to modify xml file once we change the argument in SendRedirect?
what if it was a doPost in servlet1? then using URL rewrite wouldn't work right?
In this video,instead of using doGet if I use doPost why it is not working
same problem here
change method="post" in index.html file
Yes..I did that..But still its not working
i have the same doubt
Try these steps-
1. in index.html change method to post
2. create public void doPost() in AddServlet
3. create public void doGet() in SqServlet
Does anyone know what shortcut key he used to comment out multiple lines at the same time?
ctrl+shift+/ after selecting multiple lines
Will you be uploading more videos??
Sir, why aren't you using doPost method anywhere. If I use dopost why do I get an error.
Hi
If I use dopost ...then url rewriting is possible
Doubt :
res.sendRedirect("sq"); & res.sendRedirect("sq?k=");
"sq" & "sq?k=" is different right ??
While configuring at web.xml
/sq
The actual pattern mentioned at url pattern is /sq right ??
Then how it correctly run instead showing err ??
Please educate us on hashmap and concurrent HASHMAP and spring core and spring mvc , Hibernate concepts and webservices rest and soap
some of them is already there on his channel
Go to playlist and you can find spring core, mvc and hibernate
Sir I have a doubt... Wen you click on HttpServlet class you was able to open the source code of that... But I am not able to see... I can just see source not found... How can I see the source code of jar file
sir how send multiple data via sendRedirect() like we did in RequestDispatcher ?
sir can call servlet page without clicking submit button in html
Sir is sendRedirect() method has any advantage over RequestDispatcher ??
we don't have to change res object ,so if multiple calls are made to different servlets and we want to keep our res object unmodified then we should use sendRedirect
how to send the value k from the addservelt to SqServlet by not sending it in url?
how did you comment and uncomment by selecting certain portion ???
Let us know the shortcuts too..
Sir I have windows os and fedora 26 os but I'm unable to install eclipse on it....
Can you please guide me...plz
i have ubuntu and i do installed it before two days
you can find it on google or stakeoverflow
@@divyeshkumarbalar7732 she said she's unable to install
@@agustdik3696 you can still find the solution and steps to install
What abt doing with dopost
when will be next servlet videos uploaded to this series?
We have already call servlet using servlet using RequestDispacher so why we need sendRedirect.
sir if have use post method then what comes??
Add some videos on netbeans
How to do the same thing with post method ..
Sir what is the use of "?" this symbol please tell me
You use the question mark to specify a query parameter. by specifying the question mark the first server in indicating to the second server the value of k that it is suppose to take from the request that would be redirected to it.
sir , in res.sendRedirect() method u have passed a single value k , but how can i pass more than one value so that i can send two values to SqServlet...
simple friend url?n1=12&n2=34
@@javascriptwar9525 thanks for the rply .. but my doubt is not on the url ... Inside the send redirect method ... We can concadinate only a single value .. i tried to pass two values but its not working
@@VinodKumar-zx5lk
res. sendRedirect (after url?n1=12&n2=10);
try ...
Tq
Hi.. U r not giving the same name of servelt in the servlet name tag of web.xml file , so how is that mapping happening. How is the request going to SqServlet from AddServlet just with req.dispatcher("sq")??... Can u pls explain me in detail
same doubt....
could someone please explain how it is mapping?
Carefully read the contents of the deployment descriptor file web.xml
abc
com.telusko.AddServlet
abc
/add
You can clearly see here, the servlet-name is given abc at both the places and thus, this name is used for mapping the servlet, i.e. above code says that the url /add belongs to com.telusko.AddServlet. That is, the mapping is done by just putting the common values in the tags. For mapping, it is not mandatory to match the actual servlet name with the name given in the tag.
The same logic is used for mapping the SqServlet, see the further XML code:
pqr
com.telusko.SqServlet
pqr
/sq
Here, the common name pqr is used for mapping.
Thus, when the following call is made:
req.getRequestDispatcher("sq");
The control goes to the tags and checks which has the value /sq. When it is found, the control looks for the value of under the same tag which is pqr in this case. Now, the control checks the tags and it tries to find an exact match for the name pqr in the tag. When a match is found it calls the servlet specified along in the tag which is com.telusko.SqServlet in this case.
I hope, you understood well.!!
@@yt.user-zull perfect explaination
We have to assign url pattern of that servlet not servlet name!!
@@yt.user-zull
pqr
com.telusko.Somearbitraryclass
pqr
/sq?k=
pqr
com.telusko.SqServlet
pqr
/sq
suppose these two mappings exist, for correct result second mapping must be chosen but first will be chosen. How to resolve??
For this always use get method because with post it is not going to work
why this is not working using method="post" ?
answer please...
because doget accepts parameter from URL("square?sum="+sum) and hence it works whereas dopost accepts parameter from body
Because with post method k in URL is hidden(will not be shown) and can not be found with getParameter("k") in SqServlet class.
When you use method="post" it will definitely work but it is still required to define the doGet() method in the servlet to which you are redirecting the client's request. So, just define the doGet() method in the SqServlet (in this case) and you are done!
please give the code as downloadable in text ......
Why didt you used WenAnnotation here
What if we want to send redirect with 2 values ? ... can anyone send me code
no theories pl pl
You create so much confusion man
Please describe all those confusions very clearly, so that someone could help you.
RIP eyes
Please make your videos more clear