How to pass JSP implicit objects like (request, response) in Java. I want to access JSP Implicit Objects in Java code. Please suggest how to achieve this?
My Jav
You would be able to use some servlet class. for instance :
public class ActionServlet extends HttpServlet
{
public ActionServlet()
{
super();
}
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException,IOException
{
request.setCharacterEncoding("UTF-8");
String action = request.getParameter("action");
//do smth. with "action" you are able to use your class "SomeBean"
response.setContentType("text/plain");
response.setCharacterEncoding("UTF-8");
response.sendRedirect(someUrl);
}
}
you must add into the web.xml following:
ActionServlet
ActionServlet
com.your_package.servlet.ActionServlet
ActionServlet
/Action
"/Action" is your url.
I gave a simple example, I didn't take account the either GET or POST method there. Also I would advise to use JSTL. Using some scriplets in the "view" is bad style of codding:)
However, it's better to use MVC pattern(Spring/Struts).