这看起来很简单,但我不知道为什么我会遇到这样的困难......所以在 getURL 中,我返回字符串“total”。我正在尝试返回方法 handleRequest 中已有的 SAME 值“total”。建议?提前致谢!
public class Multiply implements Controller {
static int product;
private static String total;
public static String getURL(HttpServletRequest req) {
String scheme = req.getScheme(); // http
String serverName = req.getServerName(); // hostname.com
int serverPort = req.getServerPort(); // 80
String contextPath = req.getContextPath(); // /mywebapp
String servletPath = req.getServletPath(); // /servlet/MyServlet
String pathInfo = req.getPathInfo(); // /a/b;c=123
String queryString = req.getQueryString(); // d=789
String[] item = queryString.split("&");
product = 1;
for (int i = 0; i < item.length; i++) {
String[] s = item[i].split("=");
String name = s[0];
String value = s[1];
int numValue = Integer.parseInt(value);
product = product * numValue;
}
total = "" + product;
return total;
}
public ModelAndView handleRequest(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
String Mess = total;
ModelAndView modelAndView = new ModelAndView("hello");
modelAndView.addObject("message", Mess);
return modelAndView;
}
}