基于flex4技术从零开发flex博客系统: 8 using jsp and jstl
2009-05-05 12:06:05 来源:WEB开发网该文件有两个功能,添加Greeting与删除所有Greeting。它将请求通过post方式,发送到/gapp_flexblog/hello。在第2课时,我们曾用这个url地址管理一个get请求。现在修改sban.flexblog.server.HelloWorldServlet.java:
package sban.flexblog.server;
import java.io.IOException;
import javax.servlet.http.*;
import sban.flexblog.HelloWorldUsingJPA;
/**
* @author sban.li
*
*/
public class HelloWorldServlet extends HttpServlet {
public void doPost(HttpServletRequest req, HttpServletResponse resp)
throws IOException {
String action = req.getParameter("action");
if (null != action)
{
/**
* 这里权宜调用了HelloWorldUsingJPA用于操作数据,
* 事实上HelloWorldUsingJPA与HelloWorldServlet都不应该直接硬编码数据操作。
*/
HelloWorldUsingJPA operator = new HelloWorldUsingJPA();
if (action.compareTo("new") == 0)
{
String name = req.getParameter("username");
String content = req.getParameter("greetingContent");
operator.greet2(name, content);
resp.sendRedirect("/greeting_via_jsp.jsp?message=add greeting success!");
}else if (action.compareTo("delall") == 0)
{
operator.deleteAllGreetings();
resp.sendRedirect("/greeting_via_jsp.jsp?message=remove all greetings!");
}
}
}
}
更多精彩
赞助商链接