[
如果要使用URL将参数发送到servlet,则应采用这种方式
<a href="goToServlet?param1=value1¶m2=value2">Go to servlet</a>
然后检索将在请求中可用的值。
关于第二个问题。我会说不。您可以在URL中添加参数,例如
<a href="goToServlet?method=methodName¶m1=value1">Go to servlet</a>
并使用该信息来调用特定方法。
顺便说一句,如果您使用Struts之类的框架,这将更加容易,因为在Struts中,您可以将URL绑定到特定的Action方法(比如说“ servlet”)
编辑 :
您已通过以下方式定义了servlet:
@WebServlet("/servlet123")](file:///C://Users//ghz//Desktop//all//CodingDict-
Local//%E7%88%AC%E8%99%AB//pages//jsp/page_36_09.html)
您,您的servlet将在/
servlet123上可用。请参阅doc。
我已经测试过您的代码,并且可以正常工作:
@WebServlet(name = "/servlet123", urlPatterns = { "/servlet123" })public class Servlet123 extends HttpServlet { @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { resp.setContentType("text/html"); PrintWriter out = resp.getWriter(); out.write("<h2>Hello Friends! Welcome to the world of servlet annotation </h2>"); out.write("<br/>"); out.close(); }}然后,我在中调用servlet
http://localhost:8080/myApp/servlet123(如果使用myApp,则将其作为应用程序上下文)。



