4、配置struts.xml、web.xml文件
success.jsp
text/
html
result
This is the description of my J2EE component
This is the display name of my J2EE component
RandomImageServlet
com.tenghu.code.servlet.RandomImageServlet
width
130
height
40
num
4
RandomImageServlet
/verification.do
struts2
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
struts2
/*
index.jsp
5、编写测试页面
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
My JSP 'index.jsp' starting page
<script type="text/java script" src="js/jquery-1.10.2.min.js">
<script type="text/java script" src="js/jquery.form.js">
<script type="text/java script">
$(document).ready(function(){
CODE.initCode();
//验证输入
function checkInput(){
if($('#userName').val()==''){
alert('用户名不能为空!');
return false;
}
if($('#password').val()==''){
alert('密码不能为空!');
return false;
}
if($('#code').val()==''){
alert('验证码不能为空!');
return false;
}
return true;
}
//点击按钮
$('#btn').click(function(){
if(checkInput()==true){
$('#login_request').ajaxSubmit({
url:'login!testLogin',
cache:false,
type:'POST',
success:function(data){
if(data==0){
alert('验证码错误!');
//改变验证码
CODE.initCode();
}else if(data==1){
alert('登录成功!');
//提交到登录成功页面
$('#login_request')[0].submit();
}else if(data==2){
alert('用户名或密码错误!');
//改变验证码
CODE.initCode();
}
},
error:function(e){
alert('出错了!');
}
});
}
});
});
var CODE={
//初始化化验证码
initCode:function(){
$("#code_img").attr("src","verification.do rmd="+new Date().getTime())//如果需要点击图片改变图片的内容,则必须添加时间搓
.click(function(){
$(this).attr("src","verification.do rmd="+new Date().getTime());
});
}};
成功页面就部贴出来了,就是一段文字而已
显示结果:
