📄 processallcourse.java
字号:
package course.select;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import jdbc.*;
import java.sql.*;
import exception.*;
/**
* @version 1.0
* @author
*/
public class ProcessAllcourse extends HttpServlet implements Servlet {
/**
* @see javax.servlet.http.HttpServlet#void (javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
*/
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
processRequest(req,resp);
}
/**
* @see javax.servlet.http.HttpServlet#void (javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
*/
public void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
processRequest(req,resp);
}
/**
* @param req
* @param resp
*/
private void processRequest(HttpServletRequest req, HttpServletResponse resp) throws IOException
// TODO 自动生成方法存根
{
OutputStream os=resp.getOutputStream();
DataOutputStream dos=new DataOutputStream(os);
//获得向MIDlet返回所有信息的流
try
{
DatabaseConnection connection=new DatabaseConnection();
//产生与数据库连接的类的实例,可能抛出SQLException
connection.connect();
String [] allCourse=new String[connection.getTotalCourseNum()];
int [] courseID=connection.getAllCourse(allCourse);
//获得表示所用课程的字符串数组
connection.close();
dos.writeInt(allCourse.length);
//返回所有课程数量
for(int i=0;i<allCourse.length;i++)
{
dos.writeInt(courseID[i]);
dos.writeUTF(allCourse[i]);
}
//返回课程信息
}
catch(SQLException e)
{
dos.writeInt(-3);
//-3代表连接数据库错误
// 返回提示信息
}
catch(DriverException e)
{
dos.writeInt(-3);
}
finally
{
dos.close();
}
//调试用代码
/*
PrintWriter out=resp.getWriter();
out.println("ok");
*/
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -