我有一个带有多个WAR的Web应用程序。这些WARS都执行不同的功能,但有许多共同之处:Css,Js,页眉和页脚以及某些jsps来输出错误消息和事务确认。为了保持良好的可维护性,我不想在多个位置使用这些共享文件中的任何一个,而只需要一个位置。如果我编辑了一个文件,它就会显示出来。只是基本的代码管理的东西,我不认为我真的需要在这里向任何人解释这一点。在战争中共享JSP文件,在java中使用forward Servlet
对于Css和Js,我有一个根本的战争,我只是绝对解决所有的<link>
和<script>
标签。对于页眉和页脚(jsp片段),我正在使用<c:import>
,并且正在从根本战争中再次抓住。我拥有的最后一个问题是共享jsps。
我经常在用户尝试执行导致数据库更改的操作以确认事务已完成或其他需要格式化消息给用户的情况下转发给这些jsps。一个servlet可能是这样的......
public class sampleServlet extends ExtendedHttpServlet{ //ExtendedHttpServlet used to add common function to all of our HttpServlets including the foward function I use below.
public void doPost(HttpServletRequest request, HttpServletResponse response){
//Do some preperation stuff here, then...
try{
ModelJob.insertNewControlMJob(user, submit); //ModelJob is my inteface to our 'Job' Table Model...
submit.setSeqId(ModelJob.getSeqId(user, submit));
EmailFactory.SUBMIT_NEW_EMAIL.sendCMAdminEmail(user, submit, null);
EmailFactory.SUBMIT_NEW_EMAIL.sendUserEmail(user, submit, null);
req.setAttribute("color","Green");
req.setAttribute("message"," Job Successfully Submited. Sequece id : " + submit.getSeqId());
forward("/WEB-INF/TransactionResult.jsp", req, resp);
return;
}catch(Exception e){
req.setAttribute("color","Red");
req.setAttribute("message","Teradata failure : " + e.getMessage());
forward("/WEB-INF/TransactionResult.jsp", req, resp);
e.printStackTrace();
return;
}
}
}
有了这个作为前锋我称之为上述超ExtendedHttpServlet
定义:
protected void forward(String destination, HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
RequestDispatcher dispatcher = request.getRequestDispatcher(destination.toString());
dispatcher.forward(request, response);
}
但是这个我必须有TransactionResult副本.jsp在我所有的战争中,这使得维护有点痛苦。
我的问题是 - 有什么办法可以让我的转发功能找到其他WAR中的jsps转发到。或者,也许我可以在我的EAR中包含jsp,并让它在那里找到jsp文件。这是我的理解,jsps只是文件,并在运行时由特殊的servlet编译,所以我不明白为什么这不可能?
感谢任何建议/洞察力/帮助....
编辑由于一些你问哪个服务器,我目前在WebSphere v 7.0