struts2的Action方法中,直接输出js代码

一、Action直接输入js代码

struts2的Action方法,可以没有返回值,void,然后直接out.write("<script>js代码</script>")

out.println("<script>js代码</script>")

 

	/**
	 * 单个修改价格
	 * @return
	 * @author mengxianjun
	 * @throws Exception 
	 * @date 2011-4-25 上午09:30:53
	 */
	public void updatePrice() throws Exception
	{
		TCommissionId tCommissionId = new TCommissionId();
		tCommissionId.setProductNum(productNum);
		tCommissionId.setTypeNum(typeNum);
		
		commission = priceStrategyService.queryTCommissionById(tCommissionId);
		
		/*按价格修改,else按比率修改*/
		if( "prices".equals(updateType) )
		{
			fastPriceOrRatio = DoubleConvert.getDoubleByFastPrice(fastPriceOrRatio);
			Double fastCommission = DoubleConvert.getDoubleByFastCommission((money[0])-fastPriceOrRatio);
			
			commission.setFastCommission(fastCommission);
			commission.setFastPrice(fastPriceOrRatio);
			commission.setAlterDate(new Date());//修改时间
			commission.setEmployeeId(getEmpID());//处理工号
			
			priceStrategyService.updateTCommission(commission);
		}
		else
		{
			Double fastPrice = DoubleConvert.getDoubleByFastPrice((money[0])*fastPriceOrRatio);//通过比率算出实际价格
			Double fastCommission = DoubleConvert.getDoubleByFastCommission((money[0])-fastPrice);//面值-实际价格,得到佣金
			
			commission.setFastCommission(fastCommission);
			commission.setFastPrice(fastPrice);
			commission.setAlterDate(new Date());//修改时间
			commission.setEmployeeId(getEmpID());//处理工号
			
			priceStrategyService.updateTCommission(commission);
		}
		
		this.getResponse().setContentType("text/html;charset=UTF-8");
		this.getResponse().setCharacterEncoding("UTF-8");
		PrintWriter out = this.getResponse().getWriter();
		out.println("<script>alert('修改成功!');history.go(-2);window.location.reload(true);</script>");
		out.flush();
		out.close();
		return null;
	}

 

二、AJAX提交,Struts2的Action返回json数据

	/**
	 * 验证业务密码--ajax方式
	 * @author mengxianjun
	 * @throws IOException 
	 * @date 2011-6-13 下午01:33:03
	 */
	public void checkPwd2() throws IOException
	{
		PrintWriter out = this.getResponse().getWriter();
		String vp = "false";
		if( valiPass(password2) )
		{
			vp = "true";
			out.write("{\"msg\":\""+vp+"\"}");//反斜杠转义
		}
		else
		{
			vp = "false";
			out.write("{\"msg\":\""+vp+"\"}");//反斜杠转义
		}
	}

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值