我正在研究一些需要从数据库中提取数据的项目,我使用Spring MVC从DB构建模型来选择数据.
这是我的JSP页面的问题:
<form action="result" method="get" >
<table>
<thead>
<tr>
<th>Date to select:</th>
<th>Name to select:</th>
<th>Type to select:</th>
</tr>
</thead>
<tbody>
<tr>
<td><form:select path="listOfDates">
<form:option value="NONE"> --SELECT--</form:option>
<form:options items="${listOfDates}"></form:options>
</form:select>
</td>
<td><form:select path="listOfInstitutionsNames">
<form:option value="NONE"> --SELECT--</form:option>
<form:options items="${listOfInstitutionsNames}"></form:options>
</form:select>
</td>
<td>
<form:select path="listOfInstitutionsTypes">
<form:option value="NONE"> --SELECT--</form:option>
<form:options items="${listOfInstitutionsTypes}"></form:options>
</form:select>
</td>
</tr>
</tbody>
<tfoot>
<tr>
<td><input type="submit" value="???????"/></td>
</tr>
</tfoot>
</table>
</form>
Run Code Online (Sandbox Code Playgroud)
正如你可以看到我尝试使用<form:select>从Spring标签库.
问题:
但是当它用这个控制器准备我的模型时:
@Controller
public class HomeController{
@Autowired …Run Code Online (Sandbox Code Playgroud) 我想和你分享我的问题.
我在jsp页面上构建并在我的页面上<form:select>使用它<form:select>在我请求页面时用来从数据库中提取和呈现数据search.jsp,用户必须选择一个:
<form action="result" method="get" >
<table>
<tr>
<th>Date fro DB:</th>
<td><form:select path="listOfDates">
<form:option value="NONE"> --SELECT--</form:option>
<form:options items="${listOfDates}"></form:options>
</form:select>
</td>
</tr>
<tr>
<th>Name of company from DB:</th>
<td><form:select path="listOfInstitutionsNames">
<form:option value="NONE"> --SELECT--</form:option>
<form:options items="${listOfInstitutionsNames}"></form:options>
</form:select>
</td>
</tr>
<tr>
<th>Type of company from DB:</th>
<td>
<form:select path="listOfInstitutionsTypes">
<form:option value="NONE"> --SELECT--</form:option>
<form:options items="${listOfInstitutionsTypes}"></form:options>
</form:select>
</td>
</tr>
<tr>
<td><input type="submit" value="???????"/></td>
</tr>
</table>
</form>
Run Code Online (Sandbox Code Playgroud)
我需要将用户选择的请求参数传递给我的控制器,这里是控制器的代码:
@Controller
public class HomeController{
@Autowired
private ControllerSupportClass controllerSupportClass;
@RequestMapping(value="/search", method=RequestMethod.GET)
public String …Run Code Online (Sandbox Code Playgroud) 为什么可以插入String到List<Integer>在下面的代码?我有一个类将数字插入到整数列表中:
public class Main {
public static void main(String[] args) {
List<Integer> list = new ArrayList<Integer>();
list.add(2);
list.add(3);
list.add(4);
Inserter inserter = new Inserter();
inserter.insertValue(list);
System.out.print(list);
}
}
Run Code Online (Sandbox Code Playgroud)
然后,我有一个单独的类,其插入String到一个List,与所述数字串值"42":
public class Inserter {
void insertValue(List list)
{
list.add(new String("42"));
}
}
Run Code Online (Sandbox Code Playgroud)
为什么编译器不会引发编译器错误,或者运行时抛出运行时异常,例如*CastException,当我添加String到整数列表时?另外,为什么System.out.print(list)产生如下的输出而不抛出任何异常?
[2, 3, 4, 42]
Run Code Online (Sandbox Code Playgroud)
允许所有这些发生的根本原因是什么?
Spring MVC对我来说是新手.我想有一些关于Spring MVC的例子的综合文献(甚至官方文档也不容易理解).
所以我面临的问题是:
Jun 15, 2013 2:42:36 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [appServlet] in context with path [/controller] threw exception [An exception occurred processing JSP page /WEB-INF/views/index.jsp at line 27
24:
25: <form:form commandName="creationDate" method="GET" action="add">
26:
27: <form:label path="creationDate.ParticularDate">Particular Date</form:label>
28: <form:input path="creationDate.ParticularDate" />
29:
30: <form:label path="creationDate.childGoSchoolDate">Child go to School</form:label>
Stacktrace:] with root cause
org.springframework.beans.NotReadablePropertyException: Invalid property 'creationDate' of bean class [edu.demidov.dom.CreationDate]: Bean property 'creationDate' is not readable or has an invalid getter method: Does …Run Code Online (Sandbox Code Playgroud) 我有一个jQuery代码,我在互联网上找到,我想将它集成到我的jsp页面,我使用Spring表单标签.
这是jQuery代码:
(function ($) {
//??? ?????????? select ? input
var id = "test",
$id = $('#' + id),
choices = $id.find('option').map(function (n, e) {
var $e = $(e);
return {
id: $e.val(),
text: $e.text()
};
}),
width = $id.width(),
realClass = $id.get(0).className,
realId = $id.get(0).id,
$input = $('<input>',{width: width});
$id.after($input);
$id.hide();
$id.find('option').remove();
//??????????
$input.select2({
query: function (query) {
var data = {}, i;
data.results = [];
// ?????????? ?? ??? ??????
if (query.term !== "") {
data.results.push({
id: query.term, …Run Code Online (Sandbox Code Playgroud) spring-mvc ×4
jsp ×3
java ×2
spring ×2
controller ×1
css ×1
generics ×1
hibernate ×1
javascript ×1
jquery ×1
mysql ×1