request.jsp页面中有rocarsId,和ccrn两个text。
对应在数据库中表格 rocars表的msg_id,ccrn两个字段。现在要实现在界面上修改ccrn的值,ajax提交到response.jsp页面,并调用RocarsEntiy.updateCcrn方法更新对应的ccrn,最后无刷新显示
代码:
request.jsp
复制代码 代码如下:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script language="javascript"><!--
function GetXmlHttpObject(){
var xmlHttp = null;
try{
xmlHttp = new XMLHttpRequest();
}catch(e){
try{
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
}catch(e){
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
function updateCcrn(rocarsId,ccrn){
alert(rocarsId)
alert(ccrn)
xmlHttp = GetXmlHttpObject();
if(xmlHttp == null){
alert ("you browser don't support the ajax");
return;
}
var url = "./response.jsp";
url = url + "?rocarsId="+ rocarsId;
url = url + "&ccrn="+ ccrn;
url = url + "&sid ="+ Math.random();
xmlHttp.onreadystatechange = stateChanged;
xmlHttp.open("GET", url, true);
xmlHttp.send(null);
}
function getCcrn(str){
xmlHttp = GetXmlHttpObject();
if(xmlHttp == null){
alert ("you browser don't support the ajax");
return;
}
var url = "./response.jsp";
url = url + "?q="+ str;
url = url + "&sid ="+ Math.random();
xmlHttp.onreadystatechange = stateChanged;
xmlHttp.open("GET", url, true);
xmlHttp.send(null);
}
function stateChanged()
{
if(xmlHttp.readyState==4)
{
document.getElementById("rocarsccrn").value = xmlHttp.responseText;
}
}
// --></script>
</head>
<body>
<form name="form1" action="" method="post">
<label>rocarsId:</label><input type="text" name="rocarsId" value="140" />
<label>ccrn:</label><input type="text" id="rocarsccrn" name="rocarsccrn" onchange="updateCcrn(document.form1.rocarsId.value,this.value)"/>
</form>
</body>
</html>
response.jsp
复制代码 代码如下:
<%@ page language="java" contentType="text/plain; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="com.lwf.eus.util.*,java.util.*,com.lwf.eus.entity.*,com.lwf.eus.bean.*" %>
<%
String rocarsId = request.getParameter("rocarsId");
String ccrn = request.getParameter("ccrn");
System.out.println("rocarsId:" + rocarsId);
System.out.println("ccrn:" + ccrn);
RocarsEntity.updateCcrnById(rocarsId,ccrn);
out.print(ccrn);
%>
RocarsEntity.java
复制代码 代码如下:
package com.lwf.eus.entity;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Vector;
import com.lwf.eus.bean.RocarsBean;
import com.lwf.eus.util.ConnectionManager;
public class RocarsEntity {
public static Vector getRocarsList() {
Vector vRocars = new Vector();
//Connection conn = ConnectionManager.getConnection();
Connection conn = ConnectionManager.getConnectionFromDS();
Statement st = ConnectionManager.createStatement(conn);
String sql = "select msg_id,ccrn from rocars";
ResultSet rs = null;
try {
rs = st.executeQuery(sql);
while (rs.next()) {
RocarsBean rocars = new RocarsBean();
rocars.setRocarsId(rs.getString(1));
rocars.setCcrn(rs.getString(2));
vRocars.addElement(rocars);
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
try {
if (rs != null) {
rs.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
try {
if (st != null) {
st.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
try {
if (conn != null) {
conn.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
return vRocars;
}
}
public static RocarsBean getRocarsListById(String rocarsId){
Connection conn = ConnectionManager.getConnectionFromDS();
Statement st = ConnectionManager.createStatement(conn);
String sql = "select * from rocars where msg_id=" + rocarsId;
ResultSet rs = null;
RocarsBean rocars= null;
try {
rs = st.executeQuery(sql);
rocars = new RocarsBean();
while (rs.next()) {
rocars.setRocarsId(rs.getString("msg_id"));
rocars.setCcrn(rs.getString("ccrn"));
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
try {
if (rs != null) {
rs.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
try {
if (st != null) {
st.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
try {
if (conn != null) {
conn.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
return rocars;
}
}
public static void updateCcrnById(String rocarsId, String ccrn)
{
Connection conn = null;
Statement stmt = null;
try {
conn = ConnectionManager.getConnectionFromDS();
stmt = ConnectionManager.createStatement(conn);
String sqlStr = "update rocars set ccrn= '"+ ccrn + "'" + "where msg_id=" + rocarsId ;
stmt.executeUpdate(sqlStr);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally{
try {
if (stmt != null) {
stmt.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
try {
if (conn != null) {
conn.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
ConnectionManager.java
这里可以直接使用JDBC也可以调用weblogic的数据源JNDI。
复制代码 代码如下:
package com.lwf.eus.util;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;
public class ConnectionManager {
public static Connection getConnection(){
Connection conn = null;
String url = "jdbc:postgresql://192.168.0.180/getseus";
String userName = "getsdbadmin";
String pwd = "powerdb";
try {
Class.forName("org.postgresql.Driver").newInstance();
conn = DriverManager.getConnection(url,userName,pwd);
} catch (SQLException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (Exception e){
e.printStackTrace();
}
return conn;
}
public static Connection getConnectionFromDS(){
Connection conn = null;
Context ctx = null;
try {
ctx = new InitialContext();
DataSource ds = (DataSource)ctx.lookup("JNDIPG");
conn = ds.getConnection();
} catch (NamingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return conn;
}
public static Statement createStatement(Connection conn){
Statement st = null;
try {
st = conn.createStatement();
} catch (SQLException e) {
e.printStackTrace();
}
return st;
}
}
对应在数据库中表格 rocars表的msg_id,ccrn两个字段。现在要实现在界面上修改ccrn的值,ajax提交到response.jsp页面,并调用RocarsEntiy.updateCcrn方法更新对应的ccrn,最后无刷新显示
代码:
request.jsp
复制代码 代码如下:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script language="javascript"><!--
function GetXmlHttpObject(){
var xmlHttp = null;
try{
xmlHttp = new XMLHttpRequest();
}catch(e){
try{
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
}catch(e){
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
function updateCcrn(rocarsId,ccrn){
alert(rocarsId)
alert(ccrn)
xmlHttp = GetXmlHttpObject();
if(xmlHttp == null){
alert ("you browser don't support the ajax");
return;
}
var url = "./response.jsp";
url = url + "?rocarsId="+ rocarsId;
url = url + "&ccrn="+ ccrn;
url = url + "&sid ="+ Math.random();
xmlHttp.onreadystatechange = stateChanged;
xmlHttp.open("GET", url, true);
xmlHttp.send(null);
}
function getCcrn(str){
xmlHttp = GetXmlHttpObject();
if(xmlHttp == null){
alert ("you browser don't support the ajax");
return;
}
var url = "./response.jsp";
url = url + "?q="+ str;
url = url + "&sid ="+ Math.random();
xmlHttp.onreadystatechange = stateChanged;
xmlHttp.open("GET", url, true);
xmlHttp.send(null);
}
function stateChanged()
{
if(xmlHttp.readyState==4)
{
document.getElementById("rocarsccrn").value = xmlHttp.responseText;
}
}
// --></script>
</head>
<body>
<form name="form1" action="" method="post">
<label>rocarsId:</label><input type="text" name="rocarsId" value="140" />
<label>ccrn:</label><input type="text" id="rocarsccrn" name="rocarsccrn" onchange="updateCcrn(document.form1.rocarsId.value,this.value)"/>
</form>
</body>
</html>
response.jsp
复制代码 代码如下:
<%@ page language="java" contentType="text/plain; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="com.lwf.eus.util.*,java.util.*,com.lwf.eus.entity.*,com.lwf.eus.bean.*" %>
<%
String rocarsId = request.getParameter("rocarsId");
String ccrn = request.getParameter("ccrn");
System.out.println("rocarsId:" + rocarsId);
System.out.println("ccrn:" + ccrn);
RocarsEntity.updateCcrnById(rocarsId,ccrn);
out.print(ccrn);
%>
RocarsEntity.java
复制代码 代码如下:
package com.lwf.eus.entity;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Vector;
import com.lwf.eus.bean.RocarsBean;
import com.lwf.eus.util.ConnectionManager;
public class RocarsEntity {
public static Vector getRocarsList() {
Vector vRocars = new Vector();
//Connection conn = ConnectionManager.getConnection();
Connection conn = ConnectionManager.getConnectionFromDS();
Statement st = ConnectionManager.createStatement(conn);
String sql = "select msg_id,ccrn from rocars";
ResultSet rs = null;
try {
rs = st.executeQuery(sql);
while (rs.next()) {
RocarsBean rocars = new RocarsBean();
rocars.setRocarsId(rs.getString(1));
rocars.setCcrn(rs.getString(2));
vRocars.addElement(rocars);
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
try {
if (rs != null) {
rs.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
try {
if (st != null) {
st.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
try {
if (conn != null) {
conn.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
return vRocars;
}
}
public static RocarsBean getRocarsListById(String rocarsId){
Connection conn = ConnectionManager.getConnectionFromDS();
Statement st = ConnectionManager.createStatement(conn);
String sql = "select * from rocars where msg_id=" + rocarsId;
ResultSet rs = null;
RocarsBean rocars= null;
try {
rs = st.executeQuery(sql);
rocars = new RocarsBean();
while (rs.next()) {
rocars.setRocarsId(rs.getString("msg_id"));
rocars.setCcrn(rs.getString("ccrn"));
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
try {
if (rs != null) {
rs.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
try {
if (st != null) {
st.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
try {
if (conn != null) {
conn.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
return rocars;
}
}
public static void updateCcrnById(String rocarsId, String ccrn)
{
Connection conn = null;
Statement stmt = null;
try {
conn = ConnectionManager.getConnectionFromDS();
stmt = ConnectionManager.createStatement(conn);
String sqlStr = "update rocars set ccrn= '"+ ccrn + "'" + "where msg_id=" + rocarsId ;
stmt.executeUpdate(sqlStr);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally{
try {
if (stmt != null) {
stmt.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
try {
if (conn != null) {
conn.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
ConnectionManager.java
这里可以直接使用JDBC也可以调用weblogic的数据源JNDI。
复制代码 代码如下:
package com.lwf.eus.util;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;
public class ConnectionManager {
public static Connection getConnection(){
Connection conn = null;
String url = "jdbc:postgresql://192.168.0.180/getseus";
String userName = "getsdbadmin";
String pwd = "powerdb";
try {
Class.forName("org.postgresql.Driver").newInstance();
conn = DriverManager.getConnection(url,userName,pwd);
} catch (SQLException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (Exception e){
e.printStackTrace();
}
return conn;
}
public static Connection getConnectionFromDS(){
Connection conn = null;
Context ctx = null;
try {
ctx = new InitialContext();
DataSource ds = (DataSource)ctx.lookup("JNDIPG");
conn = ds.getConnection();
} catch (NamingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return conn;
}
public static Statement createStatement(Connection conn){
Statement st = null;
try {
st = conn.createStatement();
} catch (SQLException e) {
e.printStackTrace();
}
return st;
}
}
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
暂无评论...
RTX 5090要首发 性能要翻倍!三星展示GDDR7显存
三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。
首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。
据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。
更新日志
2024年11月23日
2024年11月23日
- 凤飞飞《我们的主题曲》飞跃制作[正版原抓WAV+CUE]
- 刘嘉亮《亮情歌2》[WAV+CUE][1G]
- 红馆40·谭咏麟《歌者恋歌浓情30年演唱会》3CD[低速原抓WAV+CUE][1.8G]
- 刘纬武《睡眠宝宝竖琴童谣 吉卜力工作室 白噪音安抚》[320K/MP3][193.25MB]
- 【轻音乐】曼托凡尼乐团《精选辑》2CD.1998[FLAC+CUE整轨]
- 邝美云《心中有爱》1989年香港DMIJP版1MTO东芝首版[WAV+CUE]
- 群星《情叹-发烧女声DSD》天籁女声发烧碟[WAV+CUE]
- 刘纬武《睡眠宝宝竖琴童谣 吉卜力工作室 白噪音安抚》[FLAC/分轨][748.03MB]
- 理想混蛋《Origin Sessions》[320K/MP3][37.47MB]
- 公馆青少年《我其实一点都不酷》[320K/MP3][78.78MB]
- 群星《情叹-发烧男声DSD》最值得珍藏的完美男声[WAV+CUE]
- 群星《国韵飘香·贵妃醉酒HQCD黑胶王》2CD[WAV]
- 卫兰《DAUGHTER》【低速原抓WAV+CUE】
- 公馆青少年《我其实一点都不酷》[FLAC/分轨][398.22MB]
- ZWEI《迟暮的花 (Explicit)》[320K/MP3][57.16MB]