使用jquery的ajax方法请求action类的方法

记录:使用jquery的ajax方法请求action类的方法,方法return void,

将需要返回的数据用response.getWriter().write("")返回。

js代码:


 
   
  

jsp代码:

  

struct.xml中的代码:不需要result

		
		 

		
action类中的代码:其中AbsAction继续了ActionSupport

public class ViolationsQueryAction extends AbsAction {
	public static final org.apache.commons.logging.Log logger = org.apache.commons.logging.LogFactory.getLog(ViolationsQueryActi	on.class);

	private static final long serialVersionUID = 1L;

	@Autowired
	private TourService tourSErvice;

	
	/**
	 * 获取验证码
	 */
	public void getYzm(){
		HttpServletResponse  response=null;
		try {	
			HttpServletRequest request = getRequest();
			HttpSession session = request.getSession();
			moblie = (String) session.getAttribute("mobile");
			String yzm=tourSErvice.generateYzm(moblie);
			response=this.getResponse();
			response.getWriter().write(yzm);
		} catch (Exception e) {
			logger.error(e);
			e.printStackTrace();
		}
	}
}


你可能感兴趣的:(javascript,验证码,ajax)