刚开始学习Java方面的事情,对不起,如果这很明显的话。但是,我正在阅读有关Java 6中的Spring的教程,并看到他们在视图中使用了常规的旧JSTL。
如果我在视图中使用JSTL,Spring会给我什么?如果我使用“just java”(我知道它只是Java,但我的意思是除了像Spring或Struts这样的框架),我会用什么?
感谢。
编辑:
我猜测JSTL是V.这是我的观点。如果我已经拥有没有Spring的V,那么我还没有获得Java所拥有的内容?没有Spring我必须提供什么(请不要说MC!)
编辑:也许我在问。如果我不使用Spring,Struts或类似的东西,我将在Java中使用什么样的MVC。对于MVC,使用JSTL开箱即用,对于Java 6.我还有什么其他组件(我保留JSTL是有原因的)。感谢。
答案 0 :(得分:6)
这是一个非常简单的例子。 当你在普通香草Servlet model 2中写下这样的东西时:
public class AdditionServlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException {
String x = request.getParameter("x");
String y = request.getParameter("y");
if (x == null || y == null) throw new ServletException();
try {
request.setAttribute("result",
Integer.parseInt(x) + Integer.parseInt(y));
} catch (NumberFormatException ex) {
throw new ServletException(ex);
}
request.getRequestDispatcher("/WEB-INF/jsp/calc.jsp")
.forward(request, response);
}
}
在Spring MVC中你写这个:
@Controller
public class ArithmeticController {
@RequestMapping("/add")
public String add(@RequestParam("x") int x, @RequestParam("y") int y,
Map<String, Object> model) {
model.put("result", x + y);
return "calc";
}
}
两个控制器使用相同的JSTL视图,但样板代码的数量不同。
答案 1 :(得分:0)
主要认为提供的春天是IoC,imho。