I have 3 .jsp’s. The first one asks the user for their username. Once the form is submitted it is taken to a 2nd jsp where a unique passcode is created for the user. How would I go about taking this passcode and passing it to a 3rd jsp using a socket?
Share
You can use
java.net.URLandjava.net.URLConnectionto fire and handle HTTP requests programmatically. They make use of sockets under the covers and this way you don’t need to fiddle with low level details about the HTTP protocol. You can pass parameters as query string in the URL.This way the
passcoderequest parameter is available in the 3rd JSP by${param.passcode}orrequest.getParameter("passcode")the usual way.Better is however to just include that 3rd JSP in your 2nd JSP.
This way the
passcodeis available as request attribute in the 3rd JSP by${passcode}orrequest.getAttribute("passcode")the usual way.See also:
Unrelated to the concrete question, this is however a terribly nasty hack and the purpose of this is beyond me. There’s somewhere a serious design flaw in your application. Most likely those JSPs are tight coupled with business logic which actually belongs in normal and reuseable Java classes like servlets and/or EJBs and/or JAX-WS/RS which you just import and call in your Java class the usual Java way. JSPs are meant to generate and send HTML, not to act as business services, let alone web services. See also How to avoid Java code in JSP files?