×

Loading...
Ad by
  • 最优利率和cashback可以申请特批,好信用好收入offer更好。请点链接扫码加微信咨询,Scotiabank -- Nick Zhang 6478812600。
Ad by
  • 最优利率和cashback可以申请特批,好信用好收入offer更好。请点链接扫码加微信咨询,Scotiabank -- Nick Zhang 6478812600。

Look Inside

In Query servlet, after you detemine which servlet to call, you use
try {
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("Relative_Servlet_URL_AS_STRING");
dispatcher.forward(ServletRequest request,ServletResponse response)
}
catch (java.io.IOException e) {
// error handle..
}

The above code forward ALL request and response stuffs to the new servlet.

About your second question, you need to pack the contact manager, contact list and all other non-servlet class INTO a .jar file. And then deploy at the web server as a javabean.

Then in the servlet, you will import the class using the import statement. Then you can construct contact or contact list object you mentioned above inside your servlet to process the reading and searching of the txt file.
Report

Replies, comments and Discussions:

  • 工作学习 / IT技术讨论 / 各位大虾,JAVA servlet紧急求救!
    本人的作业要求用三个JAVA servlet程序查找地址簿中的联系人:

    QueryServlet 生成一Query Page接受用户输入的查找的字符或字符串

    FirstLetterQueryServlet 生成一First Letter Query Page显示以用户输入的字符开头的所有的联系人的资料

    SurnameQueryServlet 生成一Name Query Page显示所有一字符串开头的所有联系人的资料

    我们已经做好了一个用链接表做的List,请问如何在多个servlet程序间传递输入的字符或字符串和用JAVA servlet打开多个浏览器窗口(如在Query Page中输入一字符或字符串后马上打开另一浏览器窗口显示查找结果)?

    要求不能使用JavaScript.

    多谢!
    • 1.servlet间参数传递,这是java web application的基础,post/get/session等方法都行,看看书吧. 2.<a href=...target= >
      • well, what we learned is Java programming, not servlet or java web application. but the instructor wanted us to us to use servlet to do this. really a headache. anyway, thanks.
        • then what's java programming? you say "i'm proficient in java programming, but i have no idea about get and post". faint...
          • look inside
            You can use post, or get in your form. And then use request.getParameter("parameter_name") to extract the value. That's how you pass querystring from a form to the page which process the form.

            Other method to pass parameters including use session.

            Use session.putValue("Session_vbl_Name", object) to put the value into a session vbl in one page and you can retrieve in any jsp/servlet page inside your application. To do that, just use session.getAttribute("Session_vbl_name").

            I hope this helps.
            • 多谢大虾们!再次请教,3个servlet 和其他JAVA程序之间如何传递参数?(如3个Servlet调用同一个contact list中的数据) 再次感谢!
              • What's your contact list? A database table or a txt file or????
              • Be very specific about your question if you want to get a good answer.
                • More details
                  本文发表在 rolia.net 枫下论坛Sorry, I didn't read your post in time.

                  Another contact manager program reads first name, sure name and phone number from a text file and create a Contact object with name and phone number. The the contact manager puts the object of Contact into a ordered linked list which was already created.

                  QueryServlet receives string input from the user in html(submit form). If the length of the string is 1 (one character) then it opens a new browser window and use FirstLetterQueryServlet to show all the contact with the name starting with that character.

                  If the length of the string is greater than 1 (a string) then it use SurnameQueryServlet to open a new window to show all the contacts starts with the string input.

                  Now I know how to open a new window in servlet and transfer parameters between servlet. What I am not sure is:

                  1. How to handle different input in QueryServlet (invoke different servlet with Char or String)?

                  2. How do the three servlets communicate with the contact manager program?

                  Thank you very much, Jeffery and look forward to hearing from you.更多精彩文章及讨论,请光临枫下论坛 rolia.net
                  • Look Inside
                    In Query servlet, after you detemine which servlet to call, you use
                    try {
                    RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("Relative_Servlet_URL_AS_STRING");
                    dispatcher.forward(ServletRequest request,ServletResponse response)
                    }
                    catch (java.io.IOException e) {
                    // error handle..
                    }

                    The above code forward ALL request and response stuffs to the new servlet.

                    About your second question, you need to pack the contact manager, contact list and all other non-servlet class INTO a .jar file. And then deploy at the web server as a javabean.

                    Then in the servlet, you will import the class using the import statement. Then you can construct contact or contact list object you mentioned above inside your servlet to process the reading and searching of the txt file.