从Java servlet转发到选项卡 [英] forward to a tab from java servlet

查看:53
本文介绍了从Java servlet转发到选项卡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的JSP页面中,我有一些选项卡.每个选项卡都包含一些表单字段.当我单击提交按钮时,它将调用一个servlet.处理servlet之后,是否有任何方法可以从servlet转到下一个选项卡.

In my JSP page I have some tabs. Each tab containing some form fields. When I click on the submit button, it calls a servlet. Is there any way to goto the next tab from servlet after the servlet is processed.

这是我的index.jsp标签和第一个标签的代码

Here is my code for index.jsp for tabs and the first Tab

<div class="span12">
        <div class="navbar btn-navbar">
            <div id="tabs" class="tabbable">
                <ul id="myTab" class="nav nav-tabs">
                    <li class="active"><a href="#datacollector" target="main"
                        data-toggle="tab">Data Collector</a></li>
                    <li id="fromDB" class="selectDataloadType" style="display: none;"><a
                        href="#fromDatabase" target="main" data-toggle="tab">Data Load
                            Database</a></li>
                    <li id="fromFile" class="selectDataloadType" style="display: none;"><a
                        href="#fromFiles" target="main" data-toggle="tab">Data Load
                            File</a></li>
                    <li id="email" class="selectDataloadType" style="display: none;"><a
                        href="#fromEmail" target="main" data-toggle="tab">Data Load
                            Email</a></li>
                    <li id="webServices" class="selectDataloadType"
                        style="display: none;"><a href="#fromWebServices"
                        target="main" data-toggle="tab">Data Load Web</a></li>
                    <li><a href="#datamap" target="main" data-toggle="tab">Data
                            Map</a></li>
                    <li><a href="#schedule" target="main" data-toggle="tab">Schedule</a></li>
                </ul>
                <br> <br> <br> <br> <br>
                <div id="myTabContent" class="tab-content">
                    <div class="tab-pane fade in active" id="datacollector">
                        <div class="container">
                            <div class="row">
                                <div class="span8">
                                    <form name="selectType" action="selectType" method="get">
                                        <fieldset>
                                            <label class="control-label" for="dataloadType">Data
                                                load Type:</label> <select id="dataloadType" name="dataloadType">
                                                <option>Choose Data load Type</option>
                                                <option value="fromDB">From Database</option>
                                                <option value="fromFile">From File</option>
                                                <option value="email">E-mail</option>
                                                <option value="webServices">Web Services</option>
                                            </select>
                                            <p>
                                                <button type="submit" class="btn btn-success">Submit</button>
                                            </p>
                                        </fieldset>
                                    </form>
                                </div>
                            </div>
                        </div>
                    </div>

因此,当我单击提交"按钮时,它将调用servlet.在我的servlet中,我正在处理一些东西.之后,我希望servlet重定向到相同的index.jsp并转到下一个选项卡 在我的servlet中,我尝试过

So when I click on the submit button it will call the servlet. And in my servlet I am processing something. And after that I want the servlet to redirect to the same index.jsp and to the next tab In my servlet I tried this

RequestDispatcher rd = request.getRequestDispatcher("index.jsp#fromDatabase");
rd.forward(request, response);

但是它不起作用.有什么办法吗?

But it was not working. Is there any way?

更新1

这是我的 LI 代码

<li id="fromDB" class="selectDataloadType <c:if test="${activeTab == 'fromDatabase'}">active</c:if>" style="display: none;"><a
                        href="#fromDatabase" target="main" data-toggle="tab">Data Load
                            Database</a></li>

然后在我的index.jsp中显示以下内容

And then it shows the following in my index.jsp

我知道这是由于双引号引起的.我无法纠正它.

I know this is because of double quotes. I am not able to rectify it.

推荐答案

在转发到JSP之前,servlet应该简单地确定哪个选项卡必须处于活动状态并将此信息存储在request属性中.例如:

The servlet should simply decide which tab must be active and store this information in a request attribute before forwarding to the JSP. For example:

request.setAttribute("activeTab", "fromDatabase");

并且JSP应该使用此信息来激活适当的选项卡.例如:

And the JSP should use this information to make the appropriate tab active. For example:

<li id="fromDB" class="selectDataloadType <c:if test="${activeTab == 'fromDatabase'}">active</c:if>" ... 

(以及类似的标签内容)

(and similarly for the tab content)

这篇关于从Java servlet转发到选项卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆