jbuilder一个URL错误

wgzh159 发布于 2009/05/24 19:40
阅读 298
收藏 0
/*************************************/
package struts;
import java.sql.*;
import javax.sql.*;
import java.util.*;
public class BookQuery {
    public List query(String key)throws Exception{
        String sql="select title,type,price from title where title like '%"+key+"%'";
        Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
        Connection con=DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databaseName=pubs;user=sa;password=");
        Statement st=con.createStatement();
        ResultSet rs=st.executeQuery(sql);
        List list=new ArrayList();
        while(rs.next()){
            BookVO vo=new BookVO();
            vo.setBookName(rs.getString("title"));
            vo.setBookType(rs.getString("type"));
            vo.setBookPrice(rs.getString("price"));
            list.add(vo);
        }
        con.close();
        return list;
    }
    
}
/*********************************/
package struts;

import javax.swing.JPanel;

public class BookVO extends JPanel {
        public BookVO() {
    }
    String bookName;
    String bookType;
    String bookPrice;
    public void setBookName(String s){
        bookName=s;
    }
    public String getBookName(){
        return bookName;
    }
    public void setBookType(String s){
        bookType=s;
    }
    public String getBookType(){
        return bookType;
    }
    public void setBookPrice(String s){
        bookPrice=s;
    }
    public String getBookPrice(){
        return bookPrice;
    }    
}
/********************************************/
package struts;
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class Controller extends HttpServlet {
    public Controller() {
    }
    public void init(ServletConfig config)throws ServletException{
        super.init(config);
    }
    public void doPost(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException{
        response.setContentType("text/html;charset=gb2312");
        RequestDispatcher go=null;
        String key=request.getParameter("key");
        if(key==null||key.length()<1){
            response.sendRedirect("key.jsp");
            return;
        }
        BookQuery jb=new BookQuery();
        List list=null;
        try{
            list=jb.query(key);
        }catch(Exception e){
            String info=e.toString();
            request.setAttribute("info",info);
            go=request.getRequestDispatcher("error.jsp");
            go.forward(request,response);
            return;
        }
        request.setAttribute("result",list);
        go=request.getRequestDispatcher("result.jsp");
        go.forward(request,response);
        return ;  
    }
    public void doGet(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException{
        doPost(request,response);
    }
}
/****************web.xml********************************/

                
加载中
返回顶部
顶部