日期:2014-05-16 浏览次数:20495 次
response.setContentType("text/html;charset=utf-8"); response.setCharacterEncoding("UTF-8"); PrintWriter out = null; try { out = response.getWriter(); } catch (IOException e) { e.printStackTrace(); } try { if(userId==""||userId==null){ ....//增加操作 }else { ....//修改操作 } } catch (DataIntegrityViolationException e) {// 唯一约束 e.printStackTrace(); out.print("<script>" + "alert('编码已存在,请重新输入。');" + "history.go(-1);" + "</script>"); return null; }
<bean id="exceptionResolver" class="com.adtech.e2qframe.core.define.BaseMappingExceptionResolver"> <property name="defaultErrorView" value="/error/error.jsp" /> <property name="exceptionMappings"> <props> <prop key="java.lang.Exception">/error/error.jsp</prop> <prop key="org.springframework.dao.DataIntegrityViolationException">/error/unique.jsp</prop> </props> </property> </bean>
<%@ page contentType="text/html;charset=UTF-8" isErrorPage="true" %> <script> alert('编码已存在,请重新输入。'); history.go(-1); </script>
public ModelAndView save(HttpServletRequest request, HttpServletResponse response) throws DataIntegrityViolationException,Exception { ........... if(userId==""||userId==null){ ....//增加操作 }else { ....//修改操作 } ......