Servlet端:public class MPServlet extends HttpServlet { /**
* Constructor of the object.
*/
public MPServlet() {
super();
} /**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
} /**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
List MPlist=new ArrayList();
MPService mpservice=new MPService();
try {
MPlist =mpservice.getMPinfo();
} catch (ClassNotFoundException e) {
request.setAttribute("error","数据库连接失败!!");
request.getRequestDispatcher("../error.jsp").forward(request,response);
e.printStackTrace();
} catch (SQLException e) {
request.setAttribute("error","数据库操作失败!!");
request.getRequestDispatcher("../error.jsp").forward(request,response);
e.printStackTrace();
}
OutputStream out;
ObjectOutputStream objStream;
out = response.getOutputStream();
objStream = new ObjectOutputStream(out);
objStream.writeObject(MPlist);
objStream.close();
} /**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { doGet(request,response);
} /**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occurs
*/
public void init() throws ServletException {
// Put your code here
}}applet端:URL url = new URL("http://127.0.0.1:8888/jfreechartT/MPServlet");
URLConnection con = url.openConnection();
//con.setUseCaches(false);
con.connect();
ObjectInputStream objStream = new ObjectInputStream(con.getInputStream());
System.out.println("hello");
//ObjectInputStream objStream;
// objStream = new ObjectInputStream(in);
List list= (List)objStream.readObject();
return list; 每次都出现一下错误:
java.io.IOException: Server returned HTTP response code: 500 for URL: http://127.0.0.1:8888/jfreechartT/MPServlet
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source) ObjectInputStream objStream = new ObjectInputStream(con.getInputStream());这句总是报错
这是怎么回事?
* Constructor of the object.
*/
public MPServlet() {
super();
} /**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
} /**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
List MPlist=new ArrayList();
MPService mpservice=new MPService();
try {
MPlist =mpservice.getMPinfo();
} catch (ClassNotFoundException e) {
request.setAttribute("error","数据库连接失败!!");
request.getRequestDispatcher("../error.jsp").forward(request,response);
e.printStackTrace();
} catch (SQLException e) {
request.setAttribute("error","数据库操作失败!!");
request.getRequestDispatcher("../error.jsp").forward(request,response);
e.printStackTrace();
}
OutputStream out;
ObjectOutputStream objStream;
out = response.getOutputStream();
objStream = new ObjectOutputStream(out);
objStream.writeObject(MPlist);
objStream.close();
} /**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { doGet(request,response);
} /**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occurs
*/
public void init() throws ServletException {
// Put your code here
}}applet端:URL url = new URL("http://127.0.0.1:8888/jfreechartT/MPServlet");
URLConnection con = url.openConnection();
//con.setUseCaches(false);
con.connect();
ObjectInputStream objStream = new ObjectInputStream(con.getInputStream());
System.out.println("hello");
//ObjectInputStream objStream;
// objStream = new ObjectInputStream(in);
List list= (List)objStream.readObject();
return list; 每次都出现一下错误:
java.io.IOException: Server returned HTTP response code: 500 for URL: http://127.0.0.1:8888/jfreechartT/MPServlet
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source) ObjectInputStream objStream = new ObjectInputStream(con.getInputStream());这句总是报错
这是怎么回事?
能得到正常数据不?
Servlet端先搞定再搞,注意看服务器端的日志!