jquery - 从 JSP 页面获取值到 Java 类
问题描述
我在 JSP 页面中有一个下拉菜单,我正在从此页面中选择国家代码的值。我想在其他类中获取这个国家代码,我可以使用它来获取与所选国家相对应的状态列表。
<html>
<head>
<title>Home Page</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
</head>
<body>
<button id="mybtn">Get Country</button>
<div>
<select id="output">
<script type="text/javascript">
$('#mybtn').click(function () {
$.getJSON('countryDetail', function (data) {
$("select#output > option").remove();
$.each(data, function (key, value) {
$("#output").append('<option>' + value['countryCode'] + " " + value['countryName'] + '</option>');
$("select").change(function(){
var selectedOption = $(this).find(":selected").val();
document.getElementById("Country").innerHTML = selectedOption;
var countryDetails= document.getElementById("myText").innerHTML;
});
});
});
});
</script>
</select>
<h1>"The value for Country is: " <span id="Country"></span></h1>
</body>
</html>
我要获取国家代码并在查询中使用值的 Java 类是:
@Repository
public class StateDetailDAOImpl implements StateDetailDAO {
@Autowired
private SessionFactory sessionFactory;
@Override
public List<StateDetail> getStateDetail() {
Session currentSession = sessionFactory.getCurrentSession();
Query<StateDetail> theQuery = currentSession.createQuery("from StateDetail", StateDetail.class);
List<StateDetail> StateDetails = theQuery.getResultList();
return stateDetails;
}
}
解决方案
推荐阅读
- c# - 编辑表格条目后如何重新路由并刷新上一页?
- javascript - 将对象转换为数字(数组)
- c# - 优化解析文本文件,然后上传到Excel
- c# - 根据 DataGridView 选择显示图像会引发错误
- java - 使用 JSlider 更改图像亮度
- python - 检查给定的 *args 和 **kwargs 是否满足给定的函数签名(python2中的Signature.bind())
- python - 如何使用 bash 启动多个龙卷风实例
- complex-event-processing - 使用 CEP 在几秒钟后未发生事件时触发
- node.js - 使用 IdentityServer4 在标头中传递访问和刷新令牌
- db2 - DB2 查询多选并按日期求和