我正在使用GWT,并且希望能够incrementProduct(String productName)
通过在浏览器中键入以下 URL 来调用主 RemoteServiceServlet 中的方法:
http://mywebshop.appspot.com/increment?name=pillow
为了处理这个请求,我创建了以下 HttpServlet:
public class IncrementServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
System.out.println("IncrementServlet called!");
String name = request.getParameter("name");
// Call MyRemoteServiceServlet.incrementProduct(name) somehow
}
}
并将其添加到 web.xml:
<servlet>
<servlet-name>IncrementServlet</servlet-name>
<servlet-class>x.y.z.IncrementServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>IncrementServlet</servlet-name>
<url-pattern>/increment</url-pattern>
</servlet-mapping>
- 问题1:这是一种明智的做法吗?
- 问题 2:如何从 HttpServlet 调用 incrementProduct()?