What does Spring MVC give you if you use JSTL on the view?
Just starting to learn the Java side of things, sorry if this is obvious. But, I was reading a tutorial about Spring in Java 6 and saw they were using just regular old JSTL on the view.
What does Spring give me if I am using JSTL for the view? What would I use if I used "just java" (I know it is all Java but I mean besides a framework like Spring or Struts)?
Thanks.
edit:
I guessed开发者_StackOverflow JSTL was the V. That's my point. If I already have the V without Spring, what do I get that I don't already have with Java? What would I have to provide without Spring (please don't say MC!)
edit: Maybe I'm asking. What would I use in Java for MVC if I didn't use Spring, Struts or something like that. What out of the box for MVC, with JSTL, do I have for Java 6. What other components (I am keeping JSTL for a reason). Thanks.
Here is a very simple example. When in plain vanilla Servlet model 2 you write something like this:
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);
}
}
in Spring MVC you write this:
@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";
}
}
Both controllers use the same JSTL view, but amount of the boilerplate code differs.
Main think that spring provided is IoC, imho.
精彩评论