错误信息回显jsp

action中设置状态并写回到product.jsp

Resultresult = new Result();

result.setType(0);

result.setMessage("权限不足,请登录后访问");

String json = JSONArray.toJSONString(result);

ServletActionContext.getResponse().getWriter().write(json);

product.jsp中编码,传参到index.jsp

var obj = eval(data);

if(obj.type == 0){

var msg = encodeURI(obj.message);

window.location.href="${pageContext.request.contextPath}/index.jsp?msg="+msg;

index.jsp中解码显示错误信息

<%! String s = null; %>

<%s=new String(request.getParameter("msg").getBytes("iso-8859-1"),"utf-8");

request.setAttribute("msg", s);%>

你可能感兴趣的:(错误信息回显jsp)