在做jsp项目的时候,咋个让提交的内容放到数据库中,同时又跳转到另一个页面??
1个回答
展开全部
给你举个例子
<%@ page contentType="text/html; charset=utf-8" language="java" errorPage="../exception.jsp" %>
<%@ include file="../include/common.jsp"%>
<%
String ord_id = request.getParameter("ord_id") ;
String cus_id = request.getParameter("cus_id") ;
String pre_dt = request.getParameter("pre_dt") ;
String cus_tel = request.getParameter("cus_tel") ;
String cus_fax = request.getParameter("cus_fax") ;
String cus_addr = request.getParameter("cus_addr") ;
String remark = request.getParameter("remark") ;
String ord_type = request.getParameter("ord_type") ;
String GUSER_ID = (String)session.getAttribute("com_id") ;
boolean can_next = false ;
if(cus_tel == null){cus_tel = "" ;}
if(cus_fax == null){cus_fax = "" ;}
if(cus_addr == null){cus_addr = "" ;}
if(remark == null){remark = "" ;}
if(
pre_dt.length()==8 &&
!ord_id.equals("") &&
!cus_id.equals("") &&
!"".equals(ord_type)
){
can_next = true ;
}
if(can_next){
PreparedStatement pstmt = null;
ConnOracle dbc = null;
String sql = "update TT_KEYIN_ORDM set cus_id=?,pre_dt=to_date(?,'YYYYMMDD'),del_tel=?,del_fax=?,del_addr=?,remark=?,ord_type=?,sys_dt=sysdate where com_id=? and ord_id=?" ;
dbc = new ConnOracle();
pstmt = dbc.getConnection().prepareStatement(sql);
pstmt.setString(1, cus_id) ;
pstmt.setString(2, pre_dt) ;
pstmt.setString(3, cus_tel) ;
pstmt.setString(4, cus_fax) ;
pstmt.setString(5, cus_addr) ;
pstmt.setString(6, remark) ;
pstmt.setString(7, ord_type) ;
pstmt.setString(8, com_id) ;
pstmt.setString(9, ord_id) ;
pstmt.executeUpdate();
pstmt.close();
dbc.close();
out.clear();
out.print("修改成功!");
response.sendRedirect("这里写要跳转的页面") ;
}else{
out.clear();
out.print("修改失败!资料错误!请勿输入非法字符!");
}
%>
<%@ page contentType="text/html; charset=utf-8" language="java" errorPage="../exception.jsp" %>
<%@ include file="../include/common.jsp"%>
<%
String ord_id = request.getParameter("ord_id") ;
String cus_id = request.getParameter("cus_id") ;
String pre_dt = request.getParameter("pre_dt") ;
String cus_tel = request.getParameter("cus_tel") ;
String cus_fax = request.getParameter("cus_fax") ;
String cus_addr = request.getParameter("cus_addr") ;
String remark = request.getParameter("remark") ;
String ord_type = request.getParameter("ord_type") ;
String GUSER_ID = (String)session.getAttribute("com_id") ;
boolean can_next = false ;
if(cus_tel == null){cus_tel = "" ;}
if(cus_fax == null){cus_fax = "" ;}
if(cus_addr == null){cus_addr = "" ;}
if(remark == null){remark = "" ;}
if(
pre_dt.length()==8 &&
!ord_id.equals("") &&
!cus_id.equals("") &&
!"".equals(ord_type)
){
can_next = true ;
}
if(can_next){
PreparedStatement pstmt = null;
ConnOracle dbc = null;
String sql = "update TT_KEYIN_ORDM set cus_id=?,pre_dt=to_date(?,'YYYYMMDD'),del_tel=?,del_fax=?,del_addr=?,remark=?,ord_type=?,sys_dt=sysdate where com_id=? and ord_id=?" ;
dbc = new ConnOracle();
pstmt = dbc.getConnection().prepareStatement(sql);
pstmt.setString(1, cus_id) ;
pstmt.setString(2, pre_dt) ;
pstmt.setString(3, cus_tel) ;
pstmt.setString(4, cus_fax) ;
pstmt.setString(5, cus_addr) ;
pstmt.setString(6, remark) ;
pstmt.setString(7, ord_type) ;
pstmt.setString(8, com_id) ;
pstmt.setString(9, ord_id) ;
pstmt.executeUpdate();
pstmt.close();
dbc.close();
out.clear();
out.print("修改成功!");
response.sendRedirect("这里写要跳转的页面") ;
}else{
out.clear();
out.print("修改失败!资料错误!请勿输入非法字符!");
}
%>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询