将jsp文件包含到动态html页面中

时间:2014-09-16 10:29:28

标签: java javascript jsp servlets

我有一个动态HTML页面如下。我发送HttpSerletRequest并获得响应。根据该回复,这个html内容各不相同。

在我的servlet中:

try {
        String[] return_array = initCall(urlParameters);
        if (Integer.parseInt(return_array[0]) == 0) {    //success
            System.out.println("SUCCESS");
            switch (Integer.parseInt(return_array[1])) {
                case 1:
                case 2:
                case 3:{
                    break;
                }

                case 4:  //Agent
                    System.out.println("AGENT");
                    //rd = request.getRequestDispatcher("jsp/agentMenu.jsp");

                    out_str = "<html>\n"
                            + "<head>\n"
                                /*+ "<script type=\"text/javascript\">\n"
                                + "document.onload=\"agentMenu()\"\n"
                                + "</script>\n"*/
                            + "<script src=\"js/robicash.js\">\n"
                            + "</script>\n"
                            + "</head>"
                            + "<body align=\"center\" type=\"text/javascript\" onload=\"agentMenu()\">\n"


                            + "<h2>RobiCash</h2>\n"
                            + "<div id=\"content\">\n"
                                /*+ "<h3>Agent Main Menu</h3>\n"
                                + "<table align=\"center\">\n"
                                + "<tr><td>1:</td><td><a href=\"\" onclick=\"topUp()\">Top-Up/Recharge (P2)</a></td></tr> \n"
                                + "<tr><td>2:</td><td><a href=\"#\" onclick=\"billPayment()\">Bill Payment</a></td></tr>\n"
                                + "<tr><td>3:</td><td><a href=\"agent_2.htm\">Bill Check</a></td></tr>\n"
                                + "<tr><td>4:</td><td><a href=\"agent_3.htm\">Cash IN (P2)</a></td></tr>\n"
                                + "<tr><td>5:</td><td><a href=\"agent_4.htm\">Cash OUT (P2)</a></td></tr>\n"
                                + "<tr><td>6:</td><td><a href=\"agent_5.htm\">Customer Registration</a></td></tr>\n"
                                + "<tr><td>6:</td><td><a href=\"agent_6.htm\">My Balance</a></td></tr>\n"
                                + "<tr><td>7:</td><td><a href=\"agent_7.htm\">More</a></td></tr>\n"
                                + "<tr><td>8:</td><td><a href=\"index.jsp\">Exit</a></td></tr>\n"
                                + "</table>\n"*/
                            + "</div>\n"
                            + "</body>\n"
                            + "</html>\n";
                    break;
                case 5:       //DSR
                    break;
                case 6:      //Distributor
                    break;
                case 7:      //Master Distributor
                    break;
                default:
                    break;
            }
        }  else {      //fail

        }
        getPostResponse();
    } catch (Exception e) {
        e.printStackTrace();
    }

我需要将以下jsp文件添加到此动态html页面。

<%@ page contentType="text/html; charset=iso-8859-1" language="java" %>
<script>


function billPayment(){
 document.getElementById("content").innerHTML = "<h3>Select Utility Provider</h3>"
    + "<table align=\"center\">"
    + "<tr><td>1:</td><td><a href=\"#\" onclick=\"billBPDP()\">BPDB</a></td></tr>"
    + "<tr><td>2:</td><td><a href=\"agent_1_2.htm\" onclick=\"billDESCO()\">DESCO</a></td></tr>"
    + "<tr><td>3:</td><td><a href=\"agent_1_3.htm\" onclick=\"billWASA()\">WASA</a></td></tr>"
    + "<tr><td>4:</td><td><a href=\"\"\">Main Menu</a></td></tr>"
    + "</table>";

}

function billBPDP(){
  document.getElementById("content").innerHTML = "<h3>BPDB Payment</h3>"
    + "<form action=\"BPDBServiceCall\" method=\"post\">"
    + "<table align=\"center\">"
    + "<tr><td>Customer Account No:</td><td><input name=\"accno\" type=\"text\" value=\"\"/></td></tr>"
    + "<tr><td></td></p><td align=\"center\"><input type=submit value=\"Submit\"/></td></tr>"
    + "</table>"
    + "</form>";
}


</script>

我试过以下。但它不起作用。

<jsp:include page="robicash.jsp" />

如果我使用.js文件而不是.jsp它可以正常工作。但是我不能使用.js文件,因为我必须按照以下方式调用服务。

在我的servlet中:

 @Action(value = "BPDPServiceCall", results = {
        @Result(name = "success", location = "/jsp/robicash.jsp")})

 public String callBPDPService() {
    //serviceName = "BPDPServiceCall";
    System.out.println("=====Inside BPDPServiceCall Method=====");

    url = url + "GetBPDBPaymentDetails.do?";
    request = ServletActionContext.getRequest();

    String accno = request.getParameter("accno");
    String urlParameters = "accno=" + accno;

    try {
        //String[] return_array = initCall(urlParameters);    //comment only for debugging
        String result = sendPostRequest(urlParameters);
        System.out.println(result);    //for debugging

    } catch (Exception e) {
        e.printStackTrace();
    }

    return ActionSupport.SUCCESS;

}

如果我使用robicash.js而不是robicash.jsp,则不会调用服务。

我是java EE的新手。

任何建议都将不胜感激。

0 个答案:

没有答案