I have doGet
and doPost
methods in a servlet and I have Request.getParameter("paramName")
in both of them I want to use Request.getParameter("paramName")
out of doGet
in another place in my code for example:
protected void doGet(HttpServletRequest Request, HttpServletResponse res) throws IOException {
res.setContentType("text/html");
PrintWriter pw = res.getWriter();
pw.print("Param is "+ Request.getParameter("paramName"));
}
PrintWriter out = res.getWriter();
out.write( Request.getParameter("paramName"));
Could it be possible to achieve this?
You can either pass request to the method, or pull the value into a variable and pass that to the method.
String data = Request.getParameter("paramName");
doSomethingWithData(data);
private void doSomethingWithData(String data){
System.out.println(data);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.