推荐一个免费的支持JSP、Servlet的web hosting

类别:Java 点击:0 评论:0 推荐:

  地址:http://www.mycgiserver.com

  该web hosting提供5M的免费空间,并且支持JSP、Servlet,还有Hypersonic数据库提供。我试下来感觉速度还可以,有4万多用户在使用,稳定性应该可以保证。对于J2EE方面的新手,申请一个用来练练手还是不错的。:)

  申请很简单,只要singup,然后通过一封email激活即可。

  1.对于JSP,开通以后有一个默认的测试页面helloworld.jsp,只要输入相应网址就可以运行了,看看我的吧:http://www.myjavaserver.com/~passant/helloworld.jsp

  2.对于servlet,该空间不提供自定义的web.xml的设置,大家共用相同的配置,我摸索了一下,终于知道应该这么来使用:

  首先写的servlet要放在自己申请的用户名的包中,即要这么写:package username

  比如这个例子:

codeDivStart()

package passant.hello;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;

public class Hello extends HttpServlet {
    static final private String CONTENT_TYPE = "text/html; charset=GBK";
    //Initialize global variables
    public void init() throws ServletException {
    }
    //Process the HTTP Get request
    public void doGet(HttpServletRequest request,
                      HttpServletResponse response)
        throws ServletException, IOException {
         
        response.setContentType(CONTENT_TYPE);
        PrintWriter out = response.getWriter();
        out.println("<html>");
        out.println("<head><title>Hello</title></head>");
        out.println("<body>");
        out.println("<p>hello ,这是servlet的例子.at : "+new Date()+"</p>");
        out.println("</body></html>");
    }
    //Clean up resources
    public void destroy() {
    }
}

codeDivEnd()

  把上面的文件放在目录 passant/hello/ 中,编译后,将目录hello/以及下面的文件一起上传。注意:不是目录passant/hello/(比较怪的地方)。然后运行要这样:http://www.myjavaserver.com/servlet/passant.hello.Hello

  OK,搞定。

  3.对于提供的数据库的使用我还没试过,有兴趣的可以看看下面这篇文章,应该是蛮详细的:http://www.myjavaserver.com/~buman/tutorial.html

本文地址:http://com.8s8s.com/it/it11790.htm