java - Urlrewriting using Servlet -
I am new to programming and I have written two pieces of code to know the URLting in the servlet:
& lt; Form action = "loginhidden" method = "get" & gt; Login ID: & lt; Input name = "login" & gt; & Lt; Br> Password: & lt; Input name = "pass" type = "password" & gt; & Lt; Br> & Lt; Input type = "submit" & gt; & Lt; / Form & gt;
My web The Xml file is:
& lt; Web-App & gt; & Lt; Servlet & gt; & Lt; Servlet-name & gt; Loginhidden & lt; / Servlet-name & gt; & Lt; Servlet category & gt; Loginhidden & lt; / Servlet category & gt; & Lt; / Servlet & gt; & Lt; Servlet-mapping & gt; & Lt; Servlet-name & gt; Loginhidden & lt; / Servlet-name & gt; & Lt; URL pattern & gt; / Loginhidden & lt; / URL pattern & gt; & Lt; / Servlet-mapping & gt; & Lt; Servlet & gt; & Lt; Servlet-name & gt; Loginhidden1_name & lt; / Servlet-name & gt; & Lt; Servlet category & gt; Loginhidden1_name & lt; / Servlet category & gt; & Lt; / Servlet & gt; & Lt; Servlet-mapping & gt; & Lt; Servlet-name & gt; Loginhidden1_name & lt; / Servlet-name & gt; & Lt; URL pattern & gt; / Loginhidden1_name / * & lt; / URL pattern & gt; & Lt; / Servlet-mapping & gt; & Lt; / Web application & gt;
The pieces of the code are as follows:
1.
import java.io. *; Import javax.servlet. *; Import javax.servlet.http.http. *; Public Class LoginHide HTTerviewlet {Public Zero (HTTPTPRLETEETEETE, HTTPSVette Response Ridge) throws Servicelet Expansion, IOE Expression (Reset Seatant Type ("Text / HTML"); PrintWriter Out = res.getWriter (); String Login = req.getParameter ("Login"); string pass = rake.getpermator ("pass"); if (pass.equals ("admin")) {out.println (login); out.println (pass); Out.println (" Lt; html> gt; form action = Login = 1name = Mylogin = "+ login +" & gt; "); Out.println (" Your name: & lt; Input type = text name = myname>
"); Out .println ("& lt; input type = submit" gt; "); out.println (" "); }}}
2.
import java.io. *; import javax.servlet. *; Import javax.servlet.http.http. * ; Public Class Logging 1_name HTTPSViewlet {@ Override Public Void Dogtte (HTTPR Required Request Rake, HTCPreserve Response Race) Servlet Upation, IOE Kspesheshn (Ressettnt type ( "text / html") throws; PrintWriter = Res.getWriter (out); Out.println (req.getParameter ("mylogin")); Out.println (req.getParameter ("myname")); }}
I am able to get the value of the name in my second servicelet (Login1_name), but I get the value of the login id ("mylogin") through urlrewriting.I I am not able to get an empty price for this. help please.
Thanks a lot in advance.
If you are looking to transfer control from one servlet to another, then forward it It is a simple matter that the request for another servlet does not return to the "forward" client in this case.
In your core service, finally, you want to get a RequestDispatcher, and forward to the new URL.
like
getServletContext (). GetRequestDispatcher ("/ modified / url"). Forward (request, response);
The control thread will be transferred to another servlet. IIRC, you will still end the method call in the first servlet. That is, it does not come back to your method and then call the second servlet.
If you want to post the request process for some reason, you can take advantage of it. Although a ServletFitler would be a more appropriate way to handle this matter.