我正在使用JSP - AJAX - SERVLET。需要从数据库中获取值。我在下一页中没有AJAX从JSP获取值,但需要ajax的目的是在同一页面上获取值。 这是代码: index.jsp的:
package in.ac.idrbt;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Servlet implementation class NeftRtgsCount
*/
public class NeftRtgsCount extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
// public NeftRtgsCount1() {
// super();
// TODO Auto-generated constructor stub
// }
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
//response.getWriter().append("Served at: ").append(request.getContextPath());
PrintWriter pw=response.getWriter();
response.setContentType("text/html");
String FROM_DATE = request.getParameter("date1").toUpperCase().trim();
String TO_DATE = request.getParameter("date2").toUpperCase().trim();
String TYPE =request.getParameter("type");
Connection con;
PreparedStatement ps = null;
ResultSet rs = null;
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
con = DriverManager.getConnection("jdbc:oracle:thin:@172.16.105.48:1521:sfms","sfmsbr","sfms");
if((TYPE).equals("NEFT"))
{
ps = con.prepareStatement("Select sum(NEFT_OUT) TOTAL_NEFT_OUT from (select count(*) NEFT_OUT from MHB_MSG_HDR_BR_AR where MHB_MSG_TYP in ('2184', '2185') and MHB_OWNR_ADDRS='IFTO0000001' and MHB_SEND_DATE between TO_DATE('"+FROM_DATE+"', 'DD-MON-YYYY HH24:MI:SS') and TO_DATE('"+TO_DATE+"', 'DD-MON-YYYY HH24:MI:SS') union all select count(*) NEFT_OUT from MHB_MSG_HDR_BR where MHB_MSG_TYP in ('2184', '2185') and MHB_OWNR_ADDRS='IFTO0000001' and MHB_SEND_DATE between TO_DATE('"+FROM_DATE+"', 'DD-MON-YYYY HH24:MI:SS') and TO_DATE('"+TO_DATE+"', 'DD-MON-YYYY HH24:MI:SS'))");
rs = ps.executeQuery();
while (rs.next())
{
//String NeftCount=null;
pw.println( "NEFT COUNT :"+rs.getInt(1)+"");
}
}
else if((TYPE).equals("RTGS")){
ps = con.prepareStatement("Select sum(RTGS_OUT) TOTAL_RTGS_OUT from(select count(*) RTGS_OUT from MHB_MSG_HDR_BR_AR where MHB_MSG_TYP in ('5010','5011', '5012', '5013') and MHB_OWNR_ADDRS='IFTO0000001' and MHB_SEND_DATE between TO_DATE('"+FROM_DATE+"', 'DD-MON-YYYY HH24:MI:SS') and TO_DATE('"+TO_DATE+"', 'DD-MON-YYYY HH24:MI:SS') union all select count(*) RTGS_OUT from MHB_MSG_HDR_BR where MHB_MSG_TYP in ('5010','5011', '5012', '5013') and MHB_OWNR_ADDRS='IFTO0000001' and MHB_SEND_DATE between TO_DATE('"+FROM_DATE+"', 'DD-MON-YYYY HH24:MI:SS') and TO_DATE('"+TO_DATE+"', 'DD-MON-YYYY HH24:MI:SS'))");
rs = ps.executeQuery();
while (rs.next())
{
//String NeftCount=null;
pw.println( "RTGS COUNT :"+rs.getInt(1)+"");
}
}
}
catch (SQLException e)
{
System.out.println(e);
}
catch(ClassNotFoundException ex)
{
System.out.println("ex");
}
catch (NullPointerException nullPointer)
{
System.out.println(nullPointer);
}
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
}
}
NeftRtgsCount.java
public class main {
public static void main(String args[]) {
ScalesSolution s1 = new ScalesSolution(11);
s1.println();
ScalesSolution s2 = new ScalesSolution(s1.GetSol());
s2.println();
}
}
点击Getcount后.Url更改为
npm
然后没有任何显示。