- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想以树形结构显示MySQL中的数据库。
我有一个 JSP 页面来获取数据库名称和 JavaScript 页面以树形格式显示它。
由于我是 Web 应用程序开发新手,我不知道如何在不使用 jQuery 的情况下从 JSP 页面到 JavaScript 页面获取数据库名称。我需要使用 jQuery 来实现此目的吗?
demoframeset.html
<!--------------------------------------------------------------->
<!-- Copyright (c) 2006 by Conor O'Mahony. -->
<!-- For enquiries, please email GubuSoft@GubuSoft.com. -->
<!-- Please keep all copyright notices below. -->
<!-- Original author of TreeView script is Marcelino Martins. -->
<!--------------------------------------------------------------->
<!-- This document includes the TreeView script. The TreeView -->
<!-- script can be found at http://www.TreeView.net. The -->
<!-- script is Copyright (c) 2006 by Conor O'Mahony. -->
<!--------------------------------------------------------------->
<!-- Instructions: -->
<!-- - Through the <STYLE> tag you can change the colors and -->
<!-- types of fonts to the particular needs of your site. -->
<!-- - A predefined block with black background has been -->
<!-- made for stylish people :-) -->
<!--------------------------------------------------------------->
<HEAD>
<!-- This is the <STYLE> block for the default styles. If -->
<!-- you want the black background, remove this <STYLE> -->
<!-- block. -->
<STYLE>
BODY {
background-color: white;}
TD {
font-size: 10pt;
font-family: verdana,helvetica;
text-decoration: none;
white-space:nowrap;}
A {
text-decoration: none;
color: black;}
.specialClass {
font-family:garamond;
font-size:12pt;
color:green;
font-weight:bold;
text-decoration:underline}
</STYLE>
<!-- If you want the black background, replace the contents -->
<!-- of the <STYLE> tag above with the following...
BODY {
background-color: black;}
TD {
font-size: 10pt;
font-family: verdana,helvetica;
text-decoration: none;
white-space:nowrap;}
A {
text-decoration: none;
color: white;}
<!-- This is the end of the <STYLE> contents. -->
<!-- Code for browser detection. DO NOT REMOVE. -->
<SCRIPT src="ua.js"></SCRIPT>
<!-- Infrastructure code for the TreeView. DO NOT REMOVE. -->
<SCRIPT src="ftiens4.js"></SCRIPT>
<!-- Scripts that define the tree. DO NOT REMOVE. -->
<SCRIPT src="demoFramesetNodes.js"></SCRIPT>
</HEAD>
<BODY topmargin="16" marginheight="16">
<!------------------------------------------------------------->
<!-- IMPORTANT NOTICE: -->
<!-- Removing the following link will prevent this script -->
<!-- from working. Unless you purchase the registered -->
<!-- version of TreeView, you must include this link. -->
<!-- If you make any unauthorized changes to the following -->
<!-- code, you will violate the user agreement. If you want -->
<!-- to remove the link, see the online FAQ for instructions -->
<!-- on how to obtain a version without the link. -->
<!------------------------------------------------------------->
<DIV style="position:absolute; top:0; left:0;"><TABLE border=0><TR><TD><FONT size=-2><A style="font-size:7pt;text-decoration:none;color:silver" href="http://www.treemenu.net/" target=_blank>Javascript Tree Menu</A></FONT></TD></TR></TABLE></DIV>
<!-- Build the browser's objects and display default view -->
<!-- of the tree. -->
<SCRIPT>initializeDocument()</SCRIPT>
<NOSCRIPT>
A tree for site navigation will open here if you enable JavaScript in your browser.
</NOSCRIPT>
</BODY>
demoFrameSetNodes.js
USETEXTLINKS = 1
STARTALLOPEN = 0
ICONPATH = ''
foldersTree = gFld("<i>Databases</i>", "demoFramesetRightFrame.html")
foldersTree.treeID = "Frameset"
aux11 = insFld(foldersTree, gFld("New", "Databases.jsp"))
var xmlHttp
function create()
{
xmlHttp=CreateXmlHttpObject()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
}
var url="new1.jsp"
url=url+"?dbname="+str
url=url+"&sid="+Math.random()
// out.print(url)
xmlHttp.onreadystatechange=stateChanged
xmlHttp.open("GET",url,true)
xmlHttp.send()
}
function stateChanged()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
document.getElementById("div").innerHTML=xmlHttp.responseText
}
}
function CreateXmlHttpObject()
{
var objXMLHttp=null
if (window.XMLHttpRequest)
{
objXMLHttp=new XMLHttpRequest()
}
else if (window.ActiveXObject)
{
objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
}
return objXMLHttp
}
new1.jsp
try {
String responseText = "";
String text = "";
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/", "root", "");
DatabaseMetaData dbmd = conn.getMetaData();
ResultSet ctlgs = dbmd.getCatalogs();
while (ctlgs.next()) {
text += ctlgs.getString(1) + ",";
}
} catch (Exception e) {
out.println(e);
}
最佳答案
您应该能够从请求查询字符串参数中检索数据库名称。这可以使用以下方法完成:
request.getParameter("your-param");
在您的例子中,它应该是 dbname 参数,您在 JS 文件中的 URL 中注入(inject)该参数:
try {
String dbName = request.getParameter("dbname"); // Retrive the dbname parameter
String responseText = "";
String text = "";
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/" + dbName /*Use the dbName in the schema URL*/, "root", "");
DatabaseMetaData dbmd = conn.getMetaData();
ResultSet ctlgs = dbmd.getCatalogs();
while (ctlgs.next()) {
text += ctlgs.getString(1) + ",";
}
} catch (Exception e) {
out.println(e);
}
否则,您可以简单地在 JSP 中显示数据库名称,而无需任何外部请求调用,因为您已经将数据库名称填充为 String
以逗号分隔,您可以使用 <c:forTokens>
标记来迭代您的分割数组 String
; 文字:
<c:forTokens items="${text}" delims="," var="dbname">
<c:out value="${dbname}"/><p>
</c:forTokens>
关于javascript - 从JSP页面获取数组值到外部JavaScript页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26884055/
假设我有父页面。 当我单击“打印”时,会打开一个新选项卡(页面)以进行打印预览。 我想要的是,当我单击“打印”时,父选项卡(页面)上应显示覆盖层,以停止进一步的工作,直到子选项卡关闭。 Because
我知道这是不可能的,但我想我还是会问这个问题。 我有一个 HTTPS 页面,并且正在动态创建一个表单。我想将表单发布到 HTTP 页面。在浏览器不弹出警告的情况下这可能吗?当我在 IE8 上执行此操作
在我的应用程序中,我实现了ajax 4.0客户端模板 目前我的模板位于同一个.aspx页面上。 (例如 Main.aspx) 但我想将它们外部化。(即所有 HTML 都会放在另一个页面上) 为此,我使
我目前正在构建自己的网络应用程序。在此应用程序的标题中有一个导航栏。 我将相同的导航栏添加到我的所有 html 页面,以便在页面之间导航时保持可见,并将导航元素设置为事件到我现在所在的页面。 我的
我们有一个在集成管道下运行的 IIS7 Intranet 站点,该管道主要是 ASP.Net,带有一些传统的经典 ASP 页面。该站点允许匿名访问大多数区域,但使用 Windows 身份验证来保护某些
有一个要求,我需要根据 div 标签的高度超过 700 像素的条件将大型 HTML 页面拆分为多个页面。 我还可以根据字数拆分页面。 下面的示例根据 HTML 标签分割页面,而我需要根据 div 高度
有两个 html 页面,如果在第一个页面中单击特定图像,它将转到第二个 html 页面。如果在第二个 html 页面上的任何地方单击它应该返回到第一页并将第二页完全显示在第一页的一个 div 中 1s
我有一个简单的 hello world Servant 应用程序。我需要向它添加一些静态或动态的 html 页面。我怎样才能做到这一点?在文档中没有提到它。注意我不想在 Haskell 代码中创建 h
我有两个文件 index.html 和 index2.html。这两个文件都在本地机器上的同一目录中(无法访问 PHP 等)。 我正在努力 Page Title 使用 jQuery 从 index.h
假设我有一个 JSP 页面 index.jsp User id:
我面临着一个对我来说非常陌生的情况。我会尽力让事情变得简单来解释它一步一步来。 1)在页面 A(用户表单)中,我从字段中获取一些值并将其作为 jQuery AJAX POST 发送到页面 B。这是主要
我正在尝试弄清楚如何从 buttons.html 获取用户按钮点击动态切换第二个列的可见性 userinput.html 。我正在使用 DataTables userinput.html表并认为我有
我有asp。净 mvc4 项目。 Angularjs 已集成。 我已经按照以前的要求构建了 HTML 页面和 WEB API 2。 现在出于某种原因,我必须使用 CSHTML 页面。以前我只有 web
我的网站包含大约 18 个不同的页面。以管理员身份登录后,我单击“页面”。 我看到了以下内容 All (20) | Mine (19) | Published (19) | Draft (1) No
Haskell 中每个函数都有手册页吗?换句话说,我可以在某处输入 man fst 并获取有关该函数的手册或帮助页面吗?我发现大量的功能势不可挡! 我正在使用 GHC 和 GHCi。 最佳答案 我不知
我一直在用github pages很长一段时间以来,并使用自定义域重定向功能来重定向我的 user website来自 prahladyeri.github.io到我自己的域名 https://www
我对 Github 有一个基本的了解:我知道如何创建、添加、提交、推送和克隆存储库。我也开始探索 Github 页面来托管我的项目。我的最新项目于 3 月开始并将其推送到 gh-page。从那以后,我
在尝试查看日志时,Airflow 会抛出一个带有以下消息的 oops 页面: File "/Users/user/.pyenv/versions/3.5.2/lib/python3.5/locale.
我已经按照此处列出的步骤 (https://pages.github.com/) 为我正在处理的网站设置了一个 GitHub 页面 我设置的站点当前托管在 IIS 下,并使用 URL Rewrite
我想将我的 domain.com 重定向到 openshift 页面 (openshift-app.rhcloud.com)。我已经按照描述完成了 here它有效。唯一的问题是,在任何网站上,我都不会
我是一名优秀的程序员,十分优秀!