我对java web应用程序很新,我不确定我是否在正确的道路上。我尝试阅读有关使用这三个组件(Servlet,EJB,JDBC)的正确方法的文章,但他们讲的是不同的东西。到目前为止,我所做的是:
Servlet :(这是我用来从网页上获取数据的方法)
@EJB private BranchDAO branchDAO;
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String branchID = request.getParameter("id");
String branchDesc = request.getParameter("desc");
String operation = request.getParameter("operation");
Branch branch = new Branch(branchID, branchDesc);
if(operation.equalsIgnoreCase("Add")){
branchDAO.addBranch(branch);
}else if(operation.equalsIgnoreCase("Edit")){
branchDAO.editBranch(branch);
}else if(operation.equalsIgnoreCase("Delete")){
branchDAO.deleteBranch(branch);
}
}
....
EJB :(这是我用来保存对数据库的更改)
@Stateless
@LocalBean
public class BranchDAO {
public void addBranch(Branch branch){
String sql = "INSERT INTO branch (BranchID, Description) VALUES ('"+branch.getBranchID()+"', '"+branch.getBranchDesc()+"')";
executeModifyQuery(sql);
}
...
Branch的另一个类:(基本上是分支的简单POJO)
我知道如何使用EJB概念有问题。请指导我怎么样。我还需要学习如何使用这个会话来处理会话,我听说会话bean但是经过几个小时的谷歌搜索,我发现自己迷失了。