问题描述
我用eclipse运行一个servlet的时候,程序并不会在在webbrowser里面显示而是弹出让我下载保存。如下图,请问下大家这是什么问题我需要怎么配置?源代码如下:packagecom.neversink;importjava.io.IOException;importjava.io.PrintWriter;importjavax.servlet.ServletException;importjavax.servlet.annotation.WebServlet;importjavax.servlet.http.HttpServlet;importjavax.servlet.http.HttpServletRequest;importjavax.servlet.http.HttpServletResponse;@WebServlet("/hello.view")publicclassHelloServletextendsHttpServlet{privatestaticfinallongserialVersionUID=1L;publicHelloServlet(){super();//TODOAuto-generatedconstructorstub}protectedvoiddoGet(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletException,IOException{response.setContentType("test/html;charset=UTF-8");PrintWriterout=response.getWriter();Stringname=request.getParameter("name");out.println("<html>");out.println("<head>");out.println("<title>HelloServlet</title>");out.println("</head>");out.println("<body>");out.println("<h1>Hello!"+name+"!</h1>");out.println("</body>");out.println("</html>");out.close();}/***@seeHttpServlet#doPost(HttpServletRequestrequest,HttpServletResponseresponse)*/protectedvoiddoPost(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletException,IOException{//TODOAuto-generatedmethodstub}}
解决方案
解决方案二:
你的后台代码有执行吗?将@WebServlet("/hello.view")里面的hello.view修改为hello,然后通过访问hello试试看
解决方案三:
所有浏览器都这样?