我想知道对用户输入执行表单验证的最简洁和最好的方法是什么.我见过一些开发人员实现的org.springframework.validation.Validator
.关于这一点的问题:我看到它验证了一个类.是否必须使用用户输入中的值手动填充类,然后传递给验证器?
我对用于验证用户输入的最干净,最好的方法感到困惑.我知道传统的使用方法,request.getParameter()
然后手动检查nulls
,但我不想在我的所有验证Controller
.关于这方面的一些好建议将不胜感激.我没有在这个应用程序中使用Hibernate.
我突然从jQuery得到这个错误:
错误:在初始化之前无法调用对话框上的方法; 试图调用方法'关闭'
插件
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="http://code.jquery.com/ui/1.9.1/jquery-ui.js"></script>
Run Code Online (Sandbox Code Playgroud)
jQuery代码
我在以下函数中获取这些消息:
$(document).ready(function() {
if ($('#results').html().length != 0) {
alert('has information');
$('#dialog').dialog({
modal: true,
buttons: {
Ok: function() {
// If I use $(this).dialog($(this)).dialog('close'), the UI is displayed,
// however I do not see the OK button and no errors
$(this).dialog('close');
}
}
});
} else {
alert('has no data');
}
});
Run Code Online (Sandbox Code Playgroud)
HTML
<div id="dialog" title="Server Response">
<p><span class="${icon}" style="float: left; margin: 0 7px 50px 0;"></span>
<label id="results">${results}</label>
</p>
</div>
Run Code Online (Sandbox Code Playgroud) 我有一个有两个ModelAttributes的表单,一个是公民,另一个是惩罚.这两个对象由jquery选项卡分隔.我在获取正确显示表单上的项目时遇到问题,有些正在显示,有些则没有.我指的是html元素.
当页面上有多个ModleAttributes时,我不确定Controller的外观.下面是代码的示例:
页
<title>Citizen Registration</title>
</head>
<body>
<div id="tabs">
<ul>
<li><a href="#tab1">Citizen Registration</a></li>
<li><a href="#tab2">Punishment</a></li>
</ul>
<div id="tab1">
<form:form id="citizenRegistration" name ="citizenRegistration" method="post" modelAttribute="citizens" action="citizen_registration.htm">
<div id="divRight" class="mainDiv">
<div class="divGroup" id="divCharInfo">
<fieldset>
<legend>Characteristics Info</legend>
<ol>
<li><form:label for="photo" path="photo">Select Photo</form:label>
<form:input path="photo" type="file" id="photo" title="Upload a photo"/><form:errors path="photo" id="errors"/></li>
<li>
<label>Select Gender</label>
<form:select path="genderId" id="genderId" title="Select Your Gender">
<form:options items = "${gender.genderList}" itemValue="genderId" itemLabel="genderDesc" />
</form:select>
<form:errors path="genderId" class="errors"/>
</li>
<li><form:label for="weight" path="weight">Enter Weight <i>(lbs)</i></form:label>
<form:input path="weight" id="weight" title="Enter Weight"/><form:errors path="weight" …
Run Code Online (Sandbox Code Playgroud) 我有一个输入字段,我试图使用它的类设置其值
<form:input path="userName" id="userName" title="Choose A Unique UserName" readonly="${userNameStatus}" class="formData"/>
Run Code Online (Sandbox Code Playgroud)
其呈现为:
<input id="userName" name="userName" title="Choose A Unique UserName" class="formData" type="text" value=""/>
Run Code Online (Sandbox Code Playgroud)
我使用以下jquery但这似乎不起作用.有人能告诉我哪里出错了.
$(".formData").html("");
Run Code Online (Sandbox Code Playgroud)
编辑处理事件的JQuery函数
$('#reset').click(function (){
$("#userNameErr").text("");
$('#badgeNoErr').text("");
$(".errors").html("");
$(".formData").val("");
});
Run Code Online (Sandbox Code Playgroud)
也不是$(".formData").text("")
或$(".formData").val("")
正在工作.
我有一个Controller
具有将记录保存到数据库的函数的类.我传递了几个参数到Controller
函数,但我想我可能写错了@RequestMapping
.下面是代码
调节器
@RequestMapping(value="createRoadBlock.htm", method = RequestMethod.POST)
public @ResponseBody Integer createRoadBlock(@RequestParam String purpose, @RequestParam String userName,
@RequestParam int status, @RequestParam double latAdd,
@RequestParam double longAdd, HttpServletRequest request,
HttpServletResponse response) {
int roadBlockId = 0;
try{
roadBlockId = roadBlockManager.saveRoadBlock(purpose, userName, status,latAdd,longAdd);
logger.info("Create Road Block Successful roadBlockId "+ roadBlockId);
return roadBlockId;
}catch(Exception e){
logger.error("Exception Occured In Road Block Controller "+e.getMessage());
return roadBlockId;
}
}
Run Code Online (Sandbox Code Playgroud)
Ajax请求
$.ajax({
type:'POST',
url:'createRoadBlock.htm',
contentType:"application/json",
async:false,
cache:false,
data:{purpose:f_purpose, userName:f_userName,status: f_status,latAdd: f_latAdd, longAdd:f_lngAdd},
dataType:'json' …
Run Code Online (Sandbox Code Playgroud) 我试图将图像插入签名中的BLOB字段,然后我将从表中选择并在报表上呈现.我似乎无法想象如何将图像放入表格.我做了一个插入,但是当我渲染时,只有图像的路径显示在报告上,而不是图像本身.
表
CREATE TABLE esignatures (
office NUMBER(6,0) NOT NULL,
username VARCHAR2(10) NOT NULL,
iblob BLOB NOT NULL
)
Run Code Online (Sandbox Code Playgroud)
INSERT语句(SQL)
INSERT INTO esignatures
VALUES (100, 'BOB', utl_raw.cast_to_raw('C:\pictures\image1.png'));
Run Code Online (Sandbox Code Playgroud)
我知道我确定以HEX值的形式插入String位置如何在表格中获取图像HEX值,因此当我渲染时我将看到正在显示的图像.
我试图将记录插入表中,我收到以下错误:我也尝试使用"?" 对于sql语句中的参数并得到了相同的错误.
错误
54080 [http-8084-2] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Finished creating instance of bean 'Sybase'
54080 [http-8084-2] INFO org.springframework.jdbc.support.SQLErrorCodesFactory - SQLErrorCodes loaded: [DB2, Derby, H2, HSQL, Informix, MS-SQL, MySQL, Oracle, PostgreSQL, Sybase]
54080 [http-8084-2] DEBUG org.springframework.jdbc.support.SQLErrorCodesFactory - Looking up default SQLErrorCodes for DataSource [org.apache.commons.dbcp.BasicDataSource@1e20a9a]
54083 [http-8084-2] DEBUG org.springframework.jdbc.datasource.DataSourceUtils - Fetching JDBC Connection from DataSource
54085 [http-8084-2] DEBUG org.springframework.jdbc.datasource.DataSourceUtils - Returning JDBC Connection to DataSource
54085 [http-8084-2] DEBUG org.springframework.jdbc.support.SQLErrorCodesFactory - Database product name cached for DataSource [org.apache.commons.dbcp.BasicDataSource@1e20a9a]: name is 'MySQL'
54090 [http-8084-2] …
Run Code Online (Sandbox Code Playgroud) 我想知道我是否正确地注释这些类,因为我是注释的新手:
Country.java
@Component
public class Country {
private int countryId;
private String countryName;
private String countryCode;
/**
* No args constructor
*/
public Country() {
}
/**
* @param countryId
* @param countryName
* @param countryCode
*/
public Country(int countryId, String countryName, String countryCode) {
this.countryId = countryId;
this.countryName = countryName;
this.countryCode = countryCode;
}
//getters and setters
}
Run Code Online (Sandbox Code Playgroud)
CountryDAO.java
@Repository
public interface CountryDAO {
public List<Country> getCountryList();
public void saveCountry(Country country);
public void updateCountry(Country country);
}
Run Code Online (Sandbox Code Playgroud)
JdbcCountryDAO.java
@Component
public …
Run Code Online (Sandbox Code Playgroud) 我正在尝试验证 java 中 BigDecimal 数据类型的 NULL。我能够验证 0 值,但是 NULL 会导致NULL Point Exception。我应该在异常中处理此数据类型的验证,还是可以对数据执行一些计算来验证它。下面是我迄今为止所做的一个示例:
if(crime.getCrimeLatLocation() != null & crime.getCrimeLongLocation() != null || crime.getCrimeLatLocation().compareTo(BigDecimal.ZERO) != 0 & crime.getCrimeLongLocation().compareTo(BigDecimal.ZERO) != 0){
logger.info('Valid Data');
}
Run Code Online (Sandbox Code Playgroud) 我有一个传递给页面的列表,并在运行时创建元素.我想循环遍历这些元素并为每个元素执行一些操作.Under是我的代码:对于从这个列表中创建的每个人,我想对该人进行检查.有人可以帮助我,我只会检查一次:
jQuery的:
$(document).ready(function() {
$("#userId").each(function(i){
if ($("#userId").val != '') {
alert('not null' + i);
}
});
});
Run Code Online (Sandbox Code Playgroud)
JSP:
<c:forEach items="${person}" var="person">
<input= type="text" id="userId" value="${person.userid}" />
First name:- ${person.fName} , Last Name:- ${person.lName}
</c:forEach>
Run Code Online (Sandbox Code Playgroud) java ×6
spring-mvc ×5
html ×4
jquery ×3
javascript ×2
validation ×2
annotations ×1
bigdecimal ×1
blob ×1
foreach ×1
jquery-ui ×1
loops ×1
mysql ×1
oracle ×1
oracle10g ×1
spring ×1
sql ×1
user-input ×1