【发布时间】:2011-04-06 00:23:59
【问题描述】:
我正在尝试在 netbeans 中创建一个 servlet。它必须从 html 表单中调用并从中获取一些数据。
我覆盖了 doget 和 dopost,只在其中添加了一些测试。
当我尝试运行 servlet 时,它只显示一个 hello word jsp 页面,我发现这是 servlet 默认拥有的 index.jsp 页面。
我怎样才能使 servlet 运行并实际产生一些输出?除了索引欢迎页面?
我使用哪个 url mast 来从表单调用 servlet?
第 doget 和 dopost 方法如下所示
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
ResourceBundle rb =
ResourceBundle.getBundle("LocalStrings",request.getLocale());
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head>");
String title = rb.getString("helloworld.title");
out.println("<title>" + title + "this is my anser</title>");
out.println("</head>");
out.println("</html>");
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
this.doPost(request, response);}
【问题讨论】: