#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...

Комментарии • 132

  • @sankalparora9261
    @sankalparora9261 4 года назад +8

    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.

    • @dwaynejayce4481
      @dwaynejayce4481 3 года назад

      I realize I am pretty off topic but do anybody know a good site to stream new tv shows online ?

    • @jeremiascristian521
      @jeremiascristian521 3 года назад

      @Dwayne Jayce Flixportal :D

    • @dwaynejayce4481
      @dwaynejayce4481 3 года назад

      @Jeremias Cristian thank you, I signed up and it seems like they got a lot of movies there :D Appreciate it!!

    • @jeremiascristian521
      @jeremiascristian521 3 года назад

      @Dwayne Jayce glad I could help :D

  • @simbol5638
    @simbol5638 5 лет назад +4

    Great tutorial, We enjoyed it sir. God bless You

  • @Tech_Riteshyadav
    @Tech_Riteshyadav 9 месяцев назад +1

    The session was great

  • @gokulprasanna8746
    @gokulprasanna8746 Месяц назад

    this video was amazing sirrrr!!!!!!!!!!!!

  • @kartik_2501
    @kartik_2501 5 лет назад +6

    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=".

    • @appsytech3000
      @appsytech3000 5 лет назад +1

      good Q. if you don't understand ask me

    • @ambersingh1493
      @ambersingh1493 5 лет назад

      even i want to know this.

    • @aneckumar5701
      @aneckumar5701 4 года назад

      but where is the answer?

    • @chirayujoshi1189
      @chirayujoshi1189 4 года назад +1

      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.

  • @Anubis10110
    @Anubis10110 4 года назад

    Thank you so much Navin.

  • @franciscasimirs839
    @franciscasimirs839 5 лет назад

    Thanks a lot. It really helped me to prepare for my practical examination

  • @pavanchandaluri
    @pavanchandaluri 6 лет назад +5

    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

    • @lasyagajavelli594
      @lasyagajavelli594 5 лет назад +5

      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....

    • @kreenu5035
      @kreenu5035 4 года назад

      @@lasyagajavelli594 so we can't use dopost in the case urlRewriting

    • @subhasishchakraborty7099
      @subhasishchakraborty7099 4 года назад +1

      @@kreenu5035 no we can't use post method for url rewriting

  • @Rahulkumar-dp6nb
    @Rahulkumar-dp6nb 4 года назад

    Just superb

  • @bhavanireddyboosa423
    @bhavanireddyboosa423 5 лет назад

    Thanku navin garu🙂

  • @cricketwithpranay7759
    @cricketwithpranay7759 3 года назад

    Great sir thanku so much

  • @smiley-wu1kn
    @smiley-wu1kn 3 года назад

    THANKYOUVERYMUCHHHHH!!!!!!!!!!!!!!!!!!!

  • @maksimus.ssirotkin1124
    @maksimus.ssirotkin1124 4 года назад

    Отличное видео Perfect

  • @harshithas747
    @harshithas747 3 года назад +3

    In web.xml we have mentioned sq in servlet-mapping how can it map the same after using sq?k= in send redirect.

    • @simplykrish9553
      @simplykrish9553 3 года назад +1

      we are using doGet method. That's y its working also we are using sendRedirect.

  • @preethidonthu2433
    @preethidonthu2433 3 года назад

    thanks a lot

  • @purehustler1536
    @purehustler1536 5 лет назад +9

    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

  • @mohanas6697
    @mohanas6697 6 лет назад +2

    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.

    • @AviatorBro
      @AviatorBro 6 лет назад +1

      please tell us about it too

    • @plusvision100
      @plusvision100 6 лет назад

      could you please explain it sir

  • @MrRaghavsaxena
    @MrRaghavsaxena 3 года назад

    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 ?

  • @wpatyune1631
    @wpatyune1631 4 года назад

    These two looks like similar purpose. Are these function doing the same purpose or depending on a certain occasion?

  • @spyrostomaras6267
    @spyrostomaras6267 6 лет назад

    very helpful video congratulations grom greece man

  • @shreyasparab913
    @shreyasparab913 6 лет назад +1

    Thanks Sir😊

  • @bhavaniyallavula2575
    @bhavaniyallavula2575 3 года назад +1

    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.

    • @techstudycentr
      @techstudycentr 2 года назад

      changing URL pattern and adding parameters are different.
      We have only added parameters not changed patterns.

  • @shivanshuvyas1744
    @shivanshuvyas1744 5 лет назад +3

    What if we want to send the data using post method in sendredirect() ,would we able to do so?

    • @hardiksolanki4918
      @hardiksolanki4918 4 года назад

      I have tried bt it's not working may be some another method will work .do you know?how can we do that

    • @darshangaikwad8626
      @darshangaikwad8626 3 года назад

      Yes you have to call get method from post method and write all the code in get method just invoke it through post

  • @patyue5012
    @patyue5012 4 года назад +2

    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.

    • @Shrikant_Anand
      @Shrikant_Anand 2 года назад +3

      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.

  • @TruongNguyen-lr2jf
    @TruongNguyen-lr2jf 4 года назад

    So do we should use sendRedirect or Dispatcher ?

  • @varalakshmimuninathan5968
    @varalakshmimuninathan5968 6 лет назад

    Thank you so much Sir :)

  • @elmokhliss4852
    @elmokhliss4852 4 года назад

    Thanks

  • @Saiyam28521
    @Saiyam28521 2 года назад +1

    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?

  • @blagovestkabov3685
    @blagovestkabov3685 2 года назад +2

    But what happens when we use doPost method and we can not see the values in the URL?

  • @sagarmeena0210
    @sagarmeena0210 5 лет назад

    great

  • @chirayujoshi1189
    @chirayujoshi1189 4 года назад +1

    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?

    • @LokeshKumar-wf1tx
      @LokeshKumar-wf1tx 3 года назад

      Did you get answer for this? Iam also looking for redirect for POST request

  • @surajchennoju4736
    @surajchennoju4736 6 лет назад

    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

    • @divyankshah
      @divyankshah 6 лет назад

      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

    • @yt.user-zull
      @yt.user-zull 5 лет назад +1

      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.!!

  • @greeshmats9889
    @greeshmats9889 5 лет назад

    Can we use both sendRedirect and req dispatcher together?

  • @myprofile702
    @myprofile702 6 лет назад

    Thnx sir

  • @akarshgupta5550
    @akarshgupta5550 4 года назад +1

    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

    • @chirayujoshi1189
      @chirayujoshi1189 4 года назад +1

      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.

  • @gayathrialluri7923
    @gayathrialluri7923 5 лет назад

    telusukunna sir

  • @ashutoshkabir1657
    @ashutoshkabir1657 5 лет назад +1

    Hey Iam facing an error that is HTTP 500 -INTERNAL ERROR could you please tell me the solution

  • @rameshpaidi3406
    @rameshpaidi3406 6 лет назад +1

    Hi, Im created by HTML file in one folder and another created by java file
    how to linking to two file

  • @pentainamerica
    @pentainamerica 5 месяцев назад

    dont we need to modify xml file once we change the argument in SendRedirect?

  • @tekina4493
    @tekina4493 Год назад

    what if it was a doPost in servlet1? then using URL rewrite wouldn't work right?

  • @sangeethamanikandarajan4663
    @sangeethamanikandarajan4663 6 лет назад +4

    In this video,instead of using doGet if I use doPost why it is not working

    • @alimehmood8654
      @alimehmood8654 6 лет назад +2

      same problem here

    • @AviatorBro
      @AviatorBro 6 лет назад

      change method="post" in index.html file

    • @sangeethamanikandarajan4663
      @sangeethamanikandarajan4663 6 лет назад +2

      Yes..I did that..But still its not working

    • @plusvision100
      @plusvision100 6 лет назад

      i have the same doubt

    • @AyushSourav
      @AyushSourav 6 лет назад +3

      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

  • @purehustler1536
    @purehustler1536 5 лет назад +2

    Does anyone know what shortcut key he used to comment out multiple lines at the same time?

  • @Knowledge-Computer
    @Knowledge-Computer 6 лет назад

    Will you be uploading more videos??

  • @sharathlingam3444
    @sharathlingam3444 2 года назад

    Sir, why aren't you using doPost method anywhere. If I use dopost why do I get an error.

  • @kreenu5035
    @kreenu5035 4 года назад

    Hi
    If I use dopost ...then url rewriting is possible

  • @prabhabaskar1985
    @prabhabaskar1985 3 года назад

    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 ??

  • @Ravikumar-gj6qw
    @Ravikumar-gj6qw 6 лет назад

    Please educate us on hashmap and concurrent HASHMAP and spring core and spring mvc , Hibernate concepts and webservices rest and soap

    • @divyeshkumarbalar7732
      @divyeshkumarbalar7732 6 лет назад +2

      some of them is already there on his channel
      Go to playlist and you can find spring core, mvc and hibernate

  • @kikiadda4677
    @kikiadda4677 2 года назад

    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

  • @amitkumar8396
    @amitkumar8396 3 года назад

    sir how send multiple data via sendRedirect() like we did in RequestDispatcher ?

  • @mickykumar7573
    @mickykumar7573 5 лет назад

    sir can call servlet page without clicking submit button in html

  • @abhisekmishra5245
    @abhisekmishra5245 5 лет назад

    Sir is sendRedirect() method has any advantage over RequestDispatcher ??

    • @mickyman753
      @mickyman753 2 года назад

      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

  • @prof_as
    @prof_as 5 лет назад

    how to send the value k from the addservelt to SqServlet by not sending it in url?

  • @prabhabaskar1985
    @prabhabaskar1985 3 года назад

    how did you comment and uncomment by selecting certain portion ???
    Let us know the shortcuts too..

  • @rameshwari
    @rameshwari 6 лет назад +1

    Sir I have windows os and fedora 26 os but I'm unable to install eclipse on it....
    Can you please guide me...plz

    • @aamerhijazi
      @aamerhijazi 6 лет назад

      i have ubuntu and i do installed it before two days

    • @divyeshkumarbalar7732
      @divyeshkumarbalar7732 6 лет назад +1

      you can find it on google or stakeoverflow

    • @agustdik3696
      @agustdik3696 5 лет назад +1

      @@divyeshkumarbalar7732 she said she's unable to install

    • @divyeshkumarbalar7732
      @divyeshkumarbalar7732 5 лет назад +1

      @@agustdik3696 you can still find the solution and steps to install

  • @unnatijain1939
    @unnatijain1939 5 лет назад

    What abt doing with dopost

  • @niranjanlm2010
    @niranjanlm2010 6 лет назад

    when will be next servlet videos uploaded to this series?

  • @swapnilsapkal2108
    @swapnilsapkal2108 4 года назад

    We have already call servlet using servlet using RequestDispacher so why we need sendRedirect.

  • @pradeeppal8472
    @pradeeppal8472 4 года назад

    sir if have use post method then what comes??

  • @rahulghawali7819
    @rahulghawali7819 6 лет назад

    Add some videos on netbeans

  • @padmanabhamnanduri6823
    @padmanabhamnanduri6823 6 лет назад

    How to do the same thing with post method ..

  • @rizwancreations5620
    @rizwancreations5620 5 лет назад

    Sir what is the use of "?" this symbol please tell me

    • @visionforprogramming7624
      @visionforprogramming7624 5 лет назад +1

      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.

  • @VinodKumar-zx5lk
    @VinodKumar-zx5lk 5 лет назад

    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...

    • @javascriptwar9525
      @javascriptwar9525 5 лет назад +2

      simple friend url?n1=12&n2=34

    • @VinodKumar-zx5lk
      @VinodKumar-zx5lk 5 лет назад

      @@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

    • @javascriptwar9525
      @javascriptwar9525 5 лет назад +2

      @@VinodKumar-zx5lk
      res. sendRedirect (after url?n1=12&n2=10);
      try ...

    • @VinodKumar-zx5lk
      @VinodKumar-zx5lk 5 лет назад

      Tq

  • @nagireddysrichandana7807
    @nagireddysrichandana7807 6 лет назад

    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

    • @pallisaiprasad618
      @pallisaiprasad618 5 лет назад

      same doubt....
      could someone please explain how it is mapping?

    • @yt.user-zull
      @yt.user-zull 5 лет назад +1

      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.!!

    • @manoj32csa
      @manoj32csa 5 лет назад +1

      @@yt.user-zull perfect explaination

    • @iam.devangmp
      @iam.devangmp 5 лет назад

      We have to assign url pattern of that servlet not servlet name!!

    • @jayuchawla1892
      @jayuchawla1892 5 лет назад

      @@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??

  • @rudratiwari7082
    @rudratiwari7082 3 года назад

    For this always use get method because with post it is not going to work

  • @prathmeshdongrikar7007
    @prathmeshdongrikar7007 6 лет назад

    why this is not working using method="post" ?
    answer please...

    • @kirtanashetty9938
      @kirtanashetty9938 6 лет назад

      because doget accepts parameter from URL("square?sum="+sum) and hence it works whereas dopost accepts parameter from body

    • @11maid11
      @11maid11 6 лет назад

      Because with post method k in URL is hidden(will not be shown) and can not be found with getParameter("k") in SqServlet class.

    • @yt.user-zull
      @yt.user-zull 5 лет назад

      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!

  • @arun1993apr
    @arun1993apr 6 лет назад

    please give the code as downloadable in text ......

  • @kousikdinesh6015
    @kousikdinesh6015 5 лет назад

    Why didt you used WenAnnotation here

  • @manideep_talampally
    @manideep_talampally 5 лет назад

    What if we want to send redirect with 2 values ? ... can anyone send me code

  • @PROMAN8625
    @PROMAN8625 2 года назад

    no theories pl pl

  • @saliltiwari3277
    @saliltiwari3277 6 лет назад

    You create so much confusion man

    • @yt.user-zull
      @yt.user-zull 5 лет назад +1

      Please describe all those confusions very clearly, so that someone could help you.

  • @agustdik3696
    @agustdik3696 5 лет назад

    RIP eyes
    Please make your videos more clear