0

この質問は何度も聞かれますが、どういうわけかプログラムを動作させることができません。

これが私のJavaプログラムです:

public static void main( String [] args ) {

    try {

        URL url = new URL("http://localhost:8080/mywebapp/servletname");
        URLConnection conn = url.openConnection();
        conn.setDoOutput(true);

        BufferedWriter out = 
            new BufferedWriter( new OutputStreamWriter( conn.getOutputStream() ) );
        //out.write("xml=" + param1 + "\r\n");
        out.write("xml=xmltest\r\n");
        out.flush();
        out.close();
        BufferedReader in = 
            new BufferedReader( new InputStreamReader( conn.getInputStream() ) );

        String response;
        while ( (response = in.readLine()) != null ) {
            System.out.println( response );
        }
        in.close();
    }
    catch ( MalformedURLException ex ) {
        ex.printStackTrace();
        // a real program would need to handle this exception
    }
    catch ( IOException ex ) {
        ex.printStackTrace();
        // a real program would need to handle this exception
    }
}

conn.getInputStream() の呼び出し中に例外がスローされます

例外スローは次のとおりです。

java.io.IOException: Server returned HTTP response code: 500 for URL: http://localhost:8080/webapp/servletname  at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1436)
at com.barcap.mdm.nh.cron.TestUpload.main(TestUpload.java:35)

私のサーブレットコードはここにあります:

public class servletname extends HttpServlet {
private static final long serialVersionUID = 1L;

/**
 * @see HttpServlet#HttpServlet()
 */
public servletname() {
    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
    System.out.println("GET method reached .... but it's not supported");
    throw new ServletException("'GET' method not supported. 'POST' method required.");
    //doPost(request, response);
}

/**
 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
 */
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    // TODO Auto-generated method stub
    System.out.println("POST method reached");

    response.setContentType("text/xml");
    List<UploadUserVO> list = null;
    String xml = request.getParameter("xml");
    String responseXML = "<?xml version=\"1.0\"?><response result=\"__responseString__\"></response>";

    System.out.println("XML : " + xml);
    PrintWriter out = response.getWriter();

    try {
                  // perform some task here 
               } catch (Exception e)
}}}}

誰かが私がやっていることの何が欠けているのか、何が間違っているのかを指摘できますか?

助けてくれてありがとう。

4

0 に答える 0