开发者

making a servlet in netbeans and index.jsp

i am trying to make a servlet in netbeans. It has to be called from an html form and take some data from it.

i overwrite doget and dopost putting just some testing outs in them.

when i try to run the servlet it only shows a hello word jsp page i found out that this was the index.jsp page that the servlet had by default.

How can i make the servlet run and actually make some output? other than the index welcome page?

Which url mast i use in order to call the servlet from the form?

th doget and dopost methods look like this

 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);}


How can i make the servlet run and actually make some output? other than the index welcome page?

You should dispatch the request into the desired JSP page. You can do this with RequestDispatcher.

request.getRequestDispatcher("page.jsp").forward(request, response);

Which url mast i use in order to call the servlet from the form?

The one which you've mapped in web.xml.

You should also be putting HTML in JSP page only, not in servlet. It's also not a good practice to let doGet() and doPost() do the same. The doGet() is merely there to preprocess the data before displaying in JSP. The doPost() is merely there to postprocess the data after a HTML form submit.

In the tag info about [servlets] tag here you can find a hello world example and more links about starting with JSP/servlets.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜