- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我已从 MySQL 检索记录并将其显示在 HTML 表中。 HTML 代码如下所示
<table id="hallTable">
<thead>
<tr>
<th scope="col" style="width: 10px; display:none;">#</th>
<th scope="col" style="width: 20px;">Sl No</th>
<th scope="col" style="width: 60px;">Hall Name/Number</th>
<th scope="col" style="width: 50px;">Seating Capacity</th>
<th scope="col" style="width: 75px;">Hall Location</th>
<th scope="col" style="width: 60px;">Custodian ID</th>
<th scope="col" style="width: 75px;">Custodian Name</th>
<th scope="col" style="width: 60px;">Approver ID</th>
<th scope="col" style="width: 75px;">Approver Name</th>
<th scope="col" style="width: 10px; display:none ;">Amended</th>
</tr>
</thead>
<tbody name="tblBody" id="tblBody">
<tr>
<td scope="col" style="width: 10px; display: none;">
<input type="number" id="table_id" name="table_id" class="form-control" value="5">
</td>
<td scope="col" style="width: 20px; font-weight: normal; text-align: center">1</td>
<td scope="col" style="width: 60px; font-weight: normal;">
<input type="text" id="hall_name" name="hall_name" class="form-control" onkeyup="rowEdited($(this).parent())" value="PPEG-VC">
</td>
<td scope="col" style="width: 50px; font-weight: normal; text-align: center">
<input type="text" style="text-align: center" id="hall_capacity" name="hall_capacity" onkeyup="rowEdited($(this).parent())" class="form-control" value="50">
</td>
<td scope="col" style="width: 75px; font-weight: normal; text-align: center">
<input type="text" id="hall_location" name="hall_location" onkeyup="rowEdited($(this).parent())" class="form-control" value="main" building="">
</td>
<td scope="col" style="width: 75px; font-weight: normal; text-align: center">
<input type="text" id="custodianName" name="custodianName" placeholder="Custodian Name" class="form-control custodianautocomplete ui-autocomplete-input" value="ISRO003" autocomplete="off">
</td>
<td scope="col" style="width: 75px; font-weight: normal; text-align: center">
<input type="text" id="hall_location" name="hall_location" onkeyup="rowEdited($(this).parent())" class="form-control" value="main" building="">
</td>
<td scope="col" style="width: 75px; font-weight: normal; text-align: center">
<input type="text" id="custodianName" name="custodianName" placeholder="Custodian Name" class="form-control approverautocomplete ui-autocomplete-input" value="ISRO005" autocomplete="off">
</td>
<td scope="col" style="width: 75px; font-weight: normal; text-align: center">
<input type="text" id="hall_location" name="hall_location" onkeyup="rowEdited($(this).parent())" class="form-control" value="main" building="">
</td>
<td scope="col" style="width: 10px; display: none ;">
<input type="text" id="amended" name="amended" class="form-control">
</td>
<script>
attachCustodianAutocomplete();
attachApproverAutocomplete();
</script>
</tr>
<tr>
<td scope="col" style="width: 10px; display: none;">
<input type="number" id="table_id" name="table_id" class="form-control" value="4">
</td>
<td scope="col" style="width: 20px; font-weight: normal; text-align: center">2</td>
<td scope="col" style="width: 60px; font-weight: normal;">
<input type="text" id="hall_name" name="hall_name" class="form-control" onkeyup="rowEdited($(this).parent())" value="MISD-NVC">
</td>
<td scope="col" style="width: 50px; font-weight: normal; text-align: center">
<input type="text" style="text-align: center" id="hall_capacity" name="hall_capacity" onkeyup="rowEdited($(this).parent())" class="form-control" value="35">
</td>
<td scope="col" style="width: 75px; font-weight: normal; text-align: center">
<input type="text" id="hall_location" name="hall_location" onkeyup="rowEdited($(this).parent())" class="form-control" value="MISD">
</td>
<td scope="col" style="width: 75px; font-weight: normal; text-align: center">
<input type="text" id="custodianName" name="custodianName" placeholder="Custodian Name" class="form-control custodianautocomplete ui-autocomplete-input" value="ISRO004" autocomplete="off">
</td>
<td scope="col" style="width: 75px; font-weight: normal; text-align: center">
<input type="text" id="hall_location" name="hall_location" onkeyup="rowEdited($(this).parent())" class="form-control" value="MISD">
</td>
<td scope="col" style="width: 75px; font-weight: normal; text-align: center">
<input type="text" id="custodianName" name="custodianName" placeholder="Custodian Name" class="form-control approverautocomplete ui-autocomplete-input" value="ISRO006" autocomplete="off">
</td>
<td scope="col" style="width: 75px; font-weight: normal; text-align: center">
<input type="text" id="hall_location" name="hall_location" onkeyup="rowEdited($(this).parent())" class="form-control" value="MISD">
</td>
<td scope="col" style="width: 10px; display: none ;">
<input type="text" id="amended" name="amended" class="form-control">
</td>
<script>
attachCustodianAutocomplete();
attachApproverAutocomplete();
</script>
</tr>
</tbody>
</table>
现在,只要 Employee_ID
发生变化,我就想更新 Employee_Name
。我尝试了一切,但无法实现。 onChange js
代码是这样的
$(".custodianautocomplete").change(function() {
var IDSelected = $(this).val();
$(this).parent("td").next().find("input[name=hall_location]").val(<%=getEmpName("<script>document.writeln(IDSelected)</script>")%>);
});
我什至尝试过ajax,但这也会引发 500 错误。请帮忙给我一个解决方案。
由于没有响应,我正在添加我尝试过的其他代码。修改后的ajax代码是这样的
$(".custodianautocomplete").change(function() {
var IDSelected = $(this).val();
var yql_url = 'getEmpName.jsp';
var url = 'getEmpName.jsp';
$.ajax({
'url': yql_url,
'data': {IDSelected: IDSelected},
'success': function(response) {
console.log(response);
$(this).parent("td").next().find("input[name=hall_location]").val(response);
},
});
});
getEmpName.jsp
的代码如下
<%@page import="java.text.SimpleDateFormat"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="com.mysql.*" %>
<%@page import="java.sql.*" %>
<%@page import="java.util.*"%>
<%@page import="java.util.ArrayList"%>
<%@page import="java.io.*"%>
<%@page import="javax.servlet.*" %>
<%@page import="javax.servlet.http.*" %>
<%
String buffer = "";
String emp_id = request.getParameter("IDSelected");
try{
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/chbs?" + "user=root&password=xxx");
PreparedStatement pst = conn.prepareStatement("SELECT Employee_Name FROM users WHERE Employee_ID = ?;");
pst.setString(1, emp_id);
ResultSet rs = pst.executeQuery();
if (!resultSet.isBeforeFirst() ) {
buffer = "false";
} else {
buffer = rs.getString("users.Employee_Name");
}
pst.close();
conn.close();
}
catch (Exception e) {
e.printStackTrace();
}
return buffer;
}
%>
我尝试过的另一种ajax是这样的
$.get( "getEmpName.jsp", {
userId: IDSelected
}, function( resp ) {
console.log( resp ); // server response
$(this).parent("td").next().find("input[name=hall_location]").val( resp ); // server response
});
但是错误仍然存在
jquery-3.2.1.min.js:3049 GET http://localhost:8090/chbs/adm/getEmpName.jsp?userId=ISRO009 500 (Internal Server Error)
send @ jquery-3.2.1.min.js:3049
ajax @ jquery-3.2.1.min.js:2944
r.(anonymous function) @ jquery-3.2.1.min.js:2965
(anonymous) @ updateHallNames.jsp:250
dispatch @ jquery-3.2.1.min.js:1627
q.handle @ jquery-3.2.1.min.js:1589
jquery-3.2.1.min.js:3049 XHR failed loading: GET "http://localhost:8080/chbs/adm/getEmpName.jsp?userId=ISRO009"
我现在很绝望,因为我已经努力三天了,但仍然无法破解这个。所以请大家多多指教。
最佳答案
成功的幸福是美妙的。我做了这样的代码更改
$(".custodianautocomplete").change(function() {
var IDSelected = $(this).val();
var recovered = "Rakesh";
// $(this).parent("td").next().find("input[name=hall_location]").val("Rakesh") ;
//window.alert($(this).parent("td").next().find("input[name=hall_location]").val());
$.ajax({
url: 'getEmpName.jsp',
type : 'GET',
data : {IDSelected: IDSelected},
async: false,
success : function(response) {
recovered = response.trim();
},
fail:function (jqXHR, exception) {
console.log(jqXHR);
},
});
$(this).parent("td").next().find("input[name=hall_location]").val(recovered);
});
请注意,
fail:function (jqXHR, exception) {
console.log(jqXHR);
},
这帮助我查看了 getEmpName.jsp
中的错误。然后在同一个文件中,我将 if (!resultSet.isBeforeFirst() ) {
更改为 if (rs.next()){
并替换 return buffer;
到 out.println(buffer);
和 response.trim();
是从响应中删除空格
所必需的。代码按照我想要的方式工作。感谢 StackOverflow.com,我在这里找到了所有可能的调试方法。如果有的话,我不介意代码改进。
关于mysql - 当 HTML 值更改时,jsp 从 MySQL 检索数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48607895/
是否可以让标准 Java EE servlet 容器将文件解释并呈现为 JSP,即使该文件没有 .jsp 扩展名? 假设我的 WAR 根目录中有一个名为 foo.xyz 的文件。该文件包含一些 jST
关闭。这个问题不满足Stack Overflow guidelines .它目前不接受答案。 想改善这个问题吗?更新问题,使其成为 on-topic对于堆栈溢出。 6年前关闭。 Improve thi
我有几个通用元素(组件),它们会生成一些 html。似乎我的选择是创建一个 taglib,或者只是将该逻辑放入一个 jsp 页面并包含 jsp。 有什么不同?积极与消极? 最佳答案 Taglibs 允
我是 Ejb-JSP 的新手,对它知之甚少。我已经创建了一个 JSP 页面,它调用 Controller Servlet,而 servlet 调用 EJB。结构就像 JSP -> Servlet ->
我想编写一个自定义 JSP 标签,其输出包括其他 JSP 标签,这些标签本身也应该被动态评估。但显然我的一切TagSupport子类写入 pageContext.getOut()无需任何进一步评估,直
我有一个包含页面顶部内容的 JSP,我们称它为 header.jsp。出于性能原因,我想呈现此 JSP 并将其刷新给用户,然后再构建页面的其余部分。 (有关性能优势的解释,请参阅 here。) 我能想
我发现自己在处理一些旧的 JSP,想做一些简单的事情,比如以 dd/mm/yyyy 格式显示今天的日期 好像没那么简单, 到目前为止,我已经导入了 java.util.* 我试过很多东西 String
关于 JSP 标签字符集的简单问题。 mytag很简单。 tag文件位于 WEB-INF/tags .这个文件在 Eclipse 中的字符集是 UTF-8。出于某种原因,UTF-8 符号无法
这让我很吃惊!我的 JSP 中有以下代码。 在我重构 SlideShow 类并公开所有属性并删除 getter/setter 之前,这段代码一直有效。所以在我看来,EL 只适用于 getter 而不
现有的一组 JSP,用英文字段标签、javascript 错误/信息消息、图像“alt”消息等硬编码,需要多语言化。 将这些 JSP 转换为使用标准 Java 多语言功能(资源包、语言环境等)的最佳方
Closed. This question needs to be more focused。它当前不接受答案。 想改善这个问题吗?更新问题,使其仅通过editing this post专注于一个问题
我已经在 Tomcat 6.0 下部署了我们的 War 到 Linux 服务器。在那个 Linux 机器上,我们没有打开浏览器的权限。 是否可以从命令行执行 JSP? 最佳答案 您可以使用其中 wge
有没有人建议为 JSP 设置最佳缓冲区大小?您可以使用以下页面指令在 JSP 中设置缓冲区大小 我的问题如下 我的理解是,您使用的缓冲区大小越小,客户端浏览器的性能就越好。我的假设正确吗?如
我们正在使用 JBoss 7.1.3.Final 和 Java 6。我想将 UTF-8 页面编码应用于我们网站上提供的所有 JSP 页面,因此我将其添加到我们的 web.xml 文件中
学过jsp native,想包含动态文件。我想使用 include 调用动态页面 这段代码 如果我输入 dashboard.jsp?p=about 页面打开“pages/a
在我的 JSP 页面中,我希望链接转发到另一个 JSP 页面。当用户在 home.jsp 上时,我希望他们转到 login.jsp 等。我遇到的问题是无法找到 JSP,除非我将页面放在项目文件夹中(在
我正在尝试在新的grails应用程序中使用index.jsp切换index.gsp。我将默认的index.gsp重命名为not_index.gsp,并添加了index.jsp。现在,我收到以下错误。
是否可以从服务器端 jsf 代码将资源打开到新的浏览器选项卡(如命令按钮的 target="_newtab")? 以下代码在同一选项卡中打开资源: FacesContext.getCurrentIns
我想问一个关于 .jsp 的问题。使用 jsp 语法(例如 )和 XML 语法(例如 ... )有什么不同。使用其中一种语法是否有维护或某种 advs?谢谢。 最佳答案 原始的 语法更加紧凑,但如
JSP 文件是否有行业标准命名约定? 我遇到过来自不同来源的三种约定: 全部小写 (thisismyfile.jsp) 首字母小写的驼峰式大小写 (thisIsMyFile.jsp) 首字母大写的驼峰
我是一名优秀的程序员,十分优秀!