我正在使用@Email
注释来验证电子邮件地址.我遇到的问题是它接受像ask@stackoverflow
有效的电子邮件地址这样的东西.我想这是因为他们想要支持内部网地址,但我似乎找不到一个标志,所以它检查扩展.
我是否真的需要切换到@Pattern
(以及任何灵活的电子邮件模式的建议)或者我错过了什么?
我有一个表格,我想在其中的下一个和后退按钮.春天mvc最干净的方法是什么?只需给输入类型提交一个名称和值,并在我的控制器中检查它?
我在为我@ActionMapping
创建一个PDF文件.现在我想知道如何以保存/打开文件对话框的形式将这个pdf返回给用户?如果这一代人成功的话,我更喜欢这个显示下载链接.
我将spring-mvc 3.0.5与portlet结合使用.但是,如果有人有一些正常应用程序的指针,那么我可以从那里弄清楚.对于2.0,我读了一些关于扩展pdfgenerator类并在web.xml中进行修改的内容但是从现在开始我们只需要POJO ....
编辑:Adeel建议后的代码:
File file = new File("C:\\test.pdf");
response.setContentType("application/pdf");
try {
byte[] b = new byte[(int) file.length()];
OutputStream out = response.getPortletOutputStream();
out.write(new FileInputStream(file).read(b));
out.flush();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return "users/main";
Run Code Online (Sandbox Code Playgroud) 我创建了一个bean类并在我的控制器中使用它,但它似乎不起作用.即使我进入无效年龄,result.hasErrors
仍然是假的.
Bean类:
public class User{
@Min(13)
private int age;
private String name;
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getName(){
return name;
}
public void setName(String name){
this.name = name;
}
}
Run Code Online (Sandbox Code Playgroud)
控制器片段:
@ActionMapping(params = "myAction=validateUser")
public void validateUser(ActionRequest request, ActionResponse response, ModelMap model, @ModelAttribute("user") @Valid User user, BindingResult result ){
if(result.hasErrors()){
for(ObjectError oe : result.getAllErrors()){
System.out.println(oe.getDefaultMessage());
}
} else{
//code
}
}
Run Code Online (Sandbox Code Playgroud)
JSP:
<form:form action="${registerUser}" method="post" …
Run Code Online (Sandbox Code Playgroud) 显然,如果您尝试再次登录,liferay 不会记录当前登录的用户,实际上甚至会保持当前登录的用户处于登录状态。所以我试图强制注销。
我试过:
request.getSession().invalidate();
Run Code Online (Sandbox Code Playgroud)
但这似乎除了以某种方式破坏登录功能之外不起作用。
我想知道是否有人有其他想法如何强制注销。
编辑:
try {
HttpSession session = request.getSession();
EventsProcessorUtil.process(PropsKeys.LOGOUT_EVENTS_PRE,
PropsUtil.getArray(PropsKeys.LOGOUT_EVENTS_PRE), request, response);
String domain = CookieKeys.getDomain(request);
Cookie companyIdCookie = new Cookie(CookieKeys.COMPANY_ID,
StringPool.BLANK);
if (Validator.isNotNull(domain)) {
companyIdCookie.setDomain(domain);
}
companyIdCookie.setMaxAge(0);
companyIdCookie.setPath(StringPool.SLASH);
Cookie idCookie = new Cookie(CookieKeys.ID, StringPool.BLANK);
if (Validator.isNotNull(domain)) {
idCookie.setDomain(domain);
}
idCookie.setMaxAge(0);
idCookie.setPath(StringPool.SLASH);
Cookie passwordCookie = new Cookie(CookieKeys.PASSWORD,
StringPool.BLANK);
if (Validator.isNotNull(domain)) {
passwordCookie.setDomain(domain);
}
passwordCookie.setMaxAge(0);
passwordCookie.setPath(StringPool.SLASH);
CookieKeys.addCookie(request, response, companyIdCookie);
CookieKeys.addCookie(request, response, idCookie);
CookieKeys.addCookie(request, response, passwordCookie);
try {
session.invalidate();
} catch (Exception e) {
}
EventsProcessorUtil.process(PropsKeys.LOGOUT_EVENTS_POST,
PropsUtil.getArray(PropsKeys.LOGOUT_EVENTS_POST), …
Run Code Online (Sandbox Code Playgroud) 我有以下html页面:
<form action="editProfile" id="userInformation">
<fieldset id="birthdate">
<label><input type="text" id="day" maxlength="2"/>/<input type="text" id="month" maxlength="2"/>/<input type="text" id="year" maxlength="2"/>
</fieldset>
<fieldset>
<label>Name</label><input type="text" id="name"/>
</fieldset>
</div>
Run Code Online (Sandbox Code Playgroud)
现在我想总是跳到下一个输入字段.我试过了:
$("#birthdate input[type=text]").keyup(function(e){
if($(this).val().length == $(this).attr('maxlength')){
$(this).next(":input").focus();
}
});
Run Code Online (Sandbox Code Playgroud)
但这似乎仍然在场内.而nextall似乎没有用,或者我错了.
编辑:我的解决方案目前为止:
if($(this).val().length == $(this).attr('maxlength')){
if($(this).parent().children().last().attr('id') == $(this).attr("id")){
$(this).parent().next().find(':input').focus();
}else{
$(this).next("input").focus();
}
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个简单的目录(文档只有4页长).我遇到的问题是,当我的鼠标确实变成一只手时,当我点击它时没有任何反应.是的,目标在另一页上.
创建目录行:
Chunk chunk = new Chunk("Contact information");
chunk.setLocalGoto("Contact information");
document.add(new Paragraph(chunk));
Run Code Online (Sandbox Code Playgroud)
其中一个目标:
Anchor anchor = new Anchor("Contact information", font1);
anchor.setName("Contact information");
Chapter chapter = new Chapter(new Paragraph(anchor), 1);
chapter.setNumberDepth(0);
document.add(chapter);
Run Code Online (Sandbox Code Playgroud)
在Goto String
与比赛Anchor name
,所以我不明白我在做什么错.
我正在做一些弹簧形式验证,但是我得到了:
Failed to convert property value of type 'java.lang.String' to required type 'ja
va.util.Date' for property 'birthdate'; nested exception is java.lang.Illega
lStateException: Cannot convert value of type [java.lang.String] to required typ
e [java.util.Date] for property 'birthdate': no matching editors or conversi
on strategy found
Run Code Online (Sandbox Code Playgroud)
但是,在我的modelAttribute表单中,我有:
@NotNull
@Past
@DateTimeFormat(style="S-")
private Date birthdate;
Run Code Online (Sandbox Code Playgroud)
我以为DateTimeFormat对此负责?
我正在使用hibernate-validator 4.0.
我正在尝试使用属性文件中的错误消息进行一些弹簧验证.但是我发现的示例似乎都是硬编码的值,或者从属性文件中获取但是使用验证器类并在那里检索它.
我的设置有点不同.我在我的请求映射中使用@Valid注释,而我的@Valid类使用@NotNull等.我已经看到一些人们做@NotNull的例子(message ="blablabla"); 但这也是硬编码的,我想将这些消息放在一个属性文件中,这样我就可以轻松地编辑它,这样我就可以在将来轻松实现i18n.
关于如何实现这一点的任何意见将不胜感激.
我正在尝试格式化存储而不在数据库中格式化的电话号码.现在我只是使用substring和String concatination来形成格式化的String,但我正在寻找更清晰/更快/更少内存密集的方法.(我并不是说只使用StringBuilder).
我查看了String.format,但只接受了参数列表(如...)而不是chararray.
我在Tomcat中部署了我的webapp,但是当我在文件名前加上\我最终在我的服务器(C)文件夹的根目录中,并且如果我不在它前面添加\我最终在bin文件夹中.前者我预料到,后者我没有.在我的webapp(userControlWebApp\images)中写入文件夹的最简洁方法是什么,因为只是做..\webapps\+ request.getContextPath()
似乎不是最干净的方式.
我在chrome中使用以下JQuery:$(this).val().length
这表示一个输入字段.现在在其他所有浏览器中都可以正常使用,但在Chrome中它有时会返回错误的值.假设我在输入字段中有3个字符,但alert($(this).val().length);
会说4.
有谁知道为什么会发生这种情况并可能解决问题?
编辑:一些代码
$("#fieldset1 input[type=text]").keyup(function(e){
if($(this).val().length == $(this).attr('maxlength')){
if($(this).parent().children().last().attr('id') == $(this).attr("id")){
$(this).parent().next().find(':input').focus();
}else{
$(this).next("input").focus();
}
}
});
Run Code Online (Sandbox Code Playgroud)
如果我注意到这种行为,我在第一次之后添加了警报.
edit2:把它放在JSFiddle:http://jsfiddle.net/QyyBV/
HTML:
<fieldset id ="test">
<input type="text" id="1" maxlength="5" size="5"/>
<input type="text" id="2" maxlength="5" size="5"/>
<input type="text" id="3" maxlength="5" size="5"/>
<input type="text" id="4" maxlength="5" size="5"/>
<input type="text" id="5" maxlength="5" size="5"/>
</fieldset>
Run Code Online (Sandbox Code Playgroud)
JavaScript的:
$(document).ready(function() {
$("#test input[type=text]").keydown(function(e){
if(e.which == 8){
if($(this).val().length == 0){
$(this).prev().focus().val($(this).prev().val());
}
}
});
$("#test input[type=text]").keyup(function(e){
if($(this).val().length == $(this).attr('maxlength') ){
if($(this).parent().children().last().attr('id') == $(this).attr("id")){ …
Run Code Online (Sandbox Code Playgroud)