views:

33

answers:

2

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

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.

BalusC
A: 

Thanks a lot but i have one more question.

how do i dispatch the request into the desired JSP page?

I am sorry but i have just started with servlets and i really dont get it

Nefeli
You should have posted this as a comment, not as an answer. As to your question, didn't you see the code line and/or the links in my answer?
BalusC