编程开发 > JSP > 文章内容

jsp工作总结(14)

2016-10-5编辑:sunny

删除文件
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.io.*"%>
<html>
<head>
<title>文件的建立、检查与删除</title>
</head><body>
<%String path=request.getRealPath("");
//out.println(path);
File f=new File(path,"File.txt");
//out.println(f);
//out.println(f.exists());

if(f.exists()){//检查File.txt是否存在
f.delete();//删除File.txt文件
out.println(path + "\\File.txt 存在,已删除。");
}else{
f.createNewFile();//在当前目录下建立一个名为File.txt的文件
out.println(path + "\\File.txt 不存在,已建立。");//输出目前所在的目录路径
}
%>
31,购物车
package bean;
import java.util.*;
import java.io.Serializable;
public class CartBean implements java.io.Serializable
{
protected Hashtable itemHashtable=new Hashtable();
public CartBean()
{
}
public void setItemHashtable(Hashtable ht)
{
itemHashtable=ht;
}
public Hashtable getItemHashtable()
{
return itemHashtable;
}
public void addItem(String bznum,String bzname,int pages,String  buy_types){
String[] item={bznum,bzname,Integer.toString(pages),buy_types};
if(itemHashtable.containsKey(bznum))
{
//String[] workItem=(String[])itemHashtable.get(bznum);
//int workQty=Integer.parseInt(workItem[2]);
//pages=pages+workQty;
//workItem[2]=Integer.toString(pages);
}
else
itemHashtable.put(bznum,item);
}
public void removeItem(String bznum)
{
if(itemHashtable.containsKey(bznum))
itemHashtable.remove(bznum);
}
//public double getcost(){
//Enumeration enum=itemHashtable.elements();
//String[] workItem;
//double totalcost=0;
//while(enum.hasMoreElements())
//{
//workItem=(String[])enum.nextElement();
//if(workItem[3].equals("A")){
//totalcost=java.lang.Math.round((Integer.parseInt(workItem[2])*0.8+30));
//}
//}
//return totalcost;
//}

public Enumeration getEnumeration()
{return itemHashtable.elements();}
public int getNumOfItems()
{Enumeration enum=itemHashtable.elements();
String[] workItem;
int num=0;
while(enum.hasMoreElements())
{workItem=(String[])enum.nextElement();
num=num+1;}return num;}} 


452,设置resin为系统服务
在运行里输入 cmd ,进入系统DOS命令模式,进入 \sun\resin\bin 目录下运行
C:\Sun\resin\bin>httpd -install
这样就会装 Resin 安装成为一个系统服务,以后开机就会自运启运.
 
451,调用sql存储过程
 
JSP 调用SQL Server存储过程- -
                                      


http://blog.csdn.net/ggjjzhzz/archive/2005/03/18/323132.aspx

创建存储过程:

use mydata;

create proc proc_members_1
as
select * from members where id between 1000 and 1005
return

 

 

package test;

import java.sql.*;

public class SqlBean {
    private Connection conn;
    private Statement stmt;
    private ResultSet rs;
    private CallableStatement cstmt;
    private synchronized Connection getConnection() throws SQLException{
        try {
            Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
            String url = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=mydata";
            Connection conn = DriverManager.getConnection(url, "sa", "");  
            return conn;
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
            throw new SQLException(e.getMessage());
        } catch (InstantiationException e) {
            e.printStackTrace();
            throw new SQLException(e.getMessage());
        } catch (IllegalAccessException e) {
            e.printStackTrace();
            throw new SQLException(e.getMessage());  
        }
    }
    public ResultSet doCallableSelect(String sql) throws SQLException {
        cstmt = conn.prepareCall(sql);
        return cstmt.executeQuery();  
    }
    public SqlBean() throws SQLException{
        conn = getConnection(); 
        stmt = conn.createStatement();
    }
    public ResultSet doSelect(String sql) throws SQLException{
        ResultSet rs = stmt.executeQuery(sql);
        return rs;
    }
    public boolean doUpdate(String sql) throws SQLException {
        int i = stmt.executeUpdate(sql);
        return 0 != i;  
    }
    public void close() throws SQLException {
        if (rs != null) rs.close();
        if (stmt != null) stmt.close();
        if (conn != null) conn.close();  
}}
调用存储过程

 <%
String sDate=request.getParameter("StartDate");
String eDate=request.getParameter("EndDate");
   // String branch=request.getParameter("branch_tb");
String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
String protocol = "jdbc:odbc:prddta";
String user="sa";
String password="home";
Class.forName(driver);
Connection connection = null;
connection = DriverManager.getConnection(protocol,user,password);
CallableStatement callstat=null;
ResultSet recordSet = null;
callstat = connection.prepareCall("{call chk_zero(?,?)}",ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
callstat.setString(1,sDate);
callstat.setString(2,eDate);
recordSet=callstat.executeQuery();
%>

jsp工作总结(12)

热点推荐

登录注册
触屏版电脑版网站地图