Example: If I have a link https://www.google.com?a=1&b=2&c=3.
How do I extract these parameters a=1,b=2 & c=3 and pass it to my java class without using servlets.
Example: If I have a link https://www.google.com?a=1&b=2&c=3.
How do I extract these parameters a=1,b=2 & c=3 and pass it to my java class without using servlets.
The parameters come to the JSP in the request
object:
request.getParameter("a") //returns the value of the "a" parameter.
Why would you not want to use a servlet? They are designed to make working with HTTP protocol easier as they work with the application server to receive request and response objects.
Anyway, to answer your question: To do this without specifically creating a servlet within your IDE, you would have to develop a class which effectively becomes a servlet. For example, your class would have to import the following:
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
You would then have to extend HTTPServlet
and have a service function which receives HTTPResposne and HTTPRequest objects as parameters.
You would then need to ensure it is built and deployed to your application server's appropriate locations.
Finally in the class, you would access the parameters using a line of code like this....
String userName = request.getParameter("userName").toString();
If you really wanted to avoid this process, you could employ a framework which provides an alternative to servlets. An example might be using Spring MVC.