关于JAVA的一个问题

大熊猫

Moderator
管理成员
VIP
注册
2002-01-16
消息
22,825
荣誉分数
127
声望点数
243
哪位高手知道如何不通过JSP,HTML Form来调用Servlet.帮帮忙,作业急着交。
 
用?肴地址?一下。
....
String servletpath="http://yourservername:8080/servlet/MyServlet"
....
 
Maybe a little bit later but I just see it.

Basically, running a servlet, you need a Java web server (which supports servlet) and your servlet only has meaning in this web server. Also, you need a clien application to invoke your servlet in your web server, in most case, we use web browser as the client application. Because most web browser using HTTP protocol so most our servlet extends HttpServlet.

So, what happens when a request come to web server:

Web brower --> A HttpRequest---> web server --> return HttpResponse.

Think about what happens when you request a html page:
http://www.liujuan.com/index.html.

The servlet happens the same way:

http://www.name.com/servlet/MyServlet. Most web server allows you to place unpackaged servlets into a particular directory so can be access through URI. Some web server allows using alias name on it so you can using that alias to access servlet directly (This mostly used on initial control servlet).

If you use HTML, code like this:

<Form method=get action="/servlet/MyServlet">
<input type=submit value="submit">
</Form>

Actually, after you submit, the URL using this format to access server:
http://www.name.com/servlet/MyServlet. so the same way.

Hope can help you.
 
I found out my html code become true, let me rewrite again:

<!--
<form method=get action="/servlet/MyServlet">
<input type=submit value="submit">
</form>
-->
 
rewrite again:

form method=get action="/servlet/MyServlet"
input type=submit value="submit"
/form
 
谢谢大家,非常感谢。
 
后退
顶部