无法跟踪发送到控制器servlet的请求

时间:2014-09-26 04:27:40

标签: javascript jsp servlets

我有一个有3帧的框架集。其中两个有jsp as" src"。 只有一个人拥有" src"作为控制者。它应该到达控制器,控制器应该向param.jsp页面发送请求,该页面通过javascript(body onload)向控制器提交表单。所以最后我应该向控制器发出两个请求。

但不知怎的,我正在向没有参数的控制器发出第三个请求。

由于这里的代码遵循命令方法,如果控制器请求没有任何命令作为参数,它会抛出异常并进入错误页面。有关如何追溯请求的想法吗?

好的......我把相关的代码部分放在这里..

我用来命中InitServlet的Url是application / InitServlet?reportCommand = LobNumberDetail

InitServlet.java

  public class InitServlet extends HttpServlet{
      public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException{
            String next = "/";
    String reportCommand=Misc.getParameter(req,"reportCommand","");
     next="/controller?formAction="+reportCommand;
     }
    }

ControllerServlet.java
-----------------------

public class ControllerServlet扩展了HttpServlet {

    public void init() throws ServletException {
    Map<String, CCDemandCommand> commands = Collections.synchronizedMap(new HashMap<String, CCDemandCommand>());
    commands.put("LobNumberDetail", new LobNumberDetailCommand());
    }

       protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

      String action = "";
            action = getNullableParm(request, "formAction", "Error");
            CCDemandCommand dc = commands.get(action);
            if (dc == null) {
                dc = commands.get("Error");
            }
            dc.execute(request, response);
            }
    }

LobNumberDetailCommand.java

public class LobNumberDetailCommand扩展了CCDemandCommand {

@Override
protected String executeCommand(HttpServletRequest request,HttpServletResponse response) throws Exception {
//do something with action and subaction
String next="";
 request.setAttribute("reportName", "LobNumberDetail");
     request.setAttribute("reportDisplayName", "Lob Number Detail Report");

next="/MainReportFrameset.jsp";
 if (subaction != null&& subaction!="") {
     if("params".equalsIgnoreCase(subaction))
     {
     next="/lobNumberDetailParam.jsp";
     }
      else if("getreport".equalsIgnoreCase(subaction))
     {
        next="/lobNumberDetailReport.jsp";
     }
     }
    return next;

}

}

&#13;
&#13;
MainReportFrameset.jsp
----------------------
<%@ page import="com.chase.Misc"
                   session="false"
%>
<%

    String sReportName =(String) request.getAttribute("reportName");
    String sReportDisplayName =(String) request.getAttribute("reportDisplayName");
    String sFrameLeftTarget ="controller?formAction="+sReportName+"&subAction=params";
     String sFrameRightTarget= "Wait.jsp";
%>
<html>
    <head>
        <title></title>
    </head>
    <frameset rows="70,*" id="frmsetMain" frameborder="0" border="0">
        <frame name="frameTop"  src="./frameTop.jsp?p_report_display_name=<%=sReportDisplayName%>" noresize scrolling="no"/> 
       <frameset cols="0,*" id="frmsetContent" frameborder="5" border="5">
       <frame name="frameLeft" src="<%=sFrameLeftTarget%>"  noresize/>  
            <frame name="frameRight" src="<%=sFrameRightTarget%>"  noresize/> 
        </frameset>
    </frameset>
</html>
&#13;
&#13;
&#13;
&#13;
&#13;
LobNumberDetailParam.jsp
-------------------------
<html>
<head>
<script language="JavaScript" type="text/javascript">
function init() {
	 document.frmParameters.submit();
      return;
}
</script>
<body topmargin="0" leftmargin="0" onload="init()">
<form name="frmParameters" id="frmParameters" action="controller"
		target="frameRight" method="post"
		onsubmit="return prepareReportRun('lobnumberdetail')">
		<input type="hidden" name="formAction" value="LobNumberDetail"/> 
		<input type="hidden" name="subAction" value="getreport" />
</form>
</body>
</head>
</html>
&#13;
&#13;
&#13;    

0 个答案:

没有答案