网络编程 | 站长之家 | 网页制作 | 图形图象 | 操作系统 | 冲浪宝典 | 软件教学 | 网络办公 | 邮件系统 | 网络安全 | 认证考试 | 系统进程
Firefox | IE | Maxthon | 迅雷 | 电驴 | BitComet | FlashGet | QQ | QQ空间 | Vista | 输入法 | Ghost | Word | Excel | wps | Powerpoint
asp | .net | php | jsp | Sql | c# | Ajax | xml | Dreamweaver | FrontPages | Javascript | css | photoshop | fireworks | Flash | Cad | Discuz!
当前位置 > 网站建设学院 > 网络编程 > Java
Tag:注入,存储过程,分页,安全,优化,xmlhttp,fso,jmail,application,session,防盗链,stream,无组件,组件,md5,乱码,缓存,加密,验证码,算法,cookies,ubb,正则表达式,水印,索引,日志,压缩,base64,url重写,上传,控件,Web.config,JDBC,函数,内存,PDF,迁移,结构,破解,编译,配置,进程,分词,IIS,Apache,Tomcat,phpmyadmin,Gzip,触发器,socket
网络编程:ASP教程,ASP.NET教程,PHP教程,JSP教程,C#教程,数据库,XML教程,Ajax,Java,Perl,Shell,VB教程,Delphi,C/C++教程,软件工程,J2EE/J2ME,移动开发
本月文章推荐
.开发线程安全的SpringWeb应用.
.Java高级学习:Java代码编写的30条.
.Struts开发指南之工作流程.
.深入WebLogic Portal .
.Java的“对象思想”学习笔记[二].
.对J2EE项目的一些体会.
.java中 中文问题详解.
.Java经验点滴:类注释文档编写方法.
.Java技巧:用Java获得IP地址.
.调试工具系列--java 正则表达式(.
.X3D实战基础讲座之十二.
.JBuilder2005实现重构之类继承体.
.EJB系列教程之一.
.用DataGrid浏览数据相关实例.
.ClearQuest管理和执行ClearCase中.
.一个记事本的源程序.
.Eclipse插件开发之定制向导.
.JAVA应用问答.
.Hibernate中各个包的作用简介.
.Java 理论与实践:哈希.

使用Resin3.0配置运行Java Servlet

发表日期:2008-1-5



  前提:正确安装JDK和Resin3.0
  这个是原始文档,我做一下注释
  Configuring the web.XML
  The following is a complete working web.xml to run this example.
  The servlet-mapping tells Resin that the URL /hello should invoke the hello-world servlet.
  The servlet tells Resin that hello-world uses the test.HelloWorld class and that the value of the greeting init parameter is Hello World.
  
  WEB-INF/web.xml
  <web-app>
  <servlet-mapping url-pattern='/hello'
  servlet-name='hello-world'/>
  
  <servlet servlet-name='hello-world'
  servlet-class='test.HelloWorld'>
  <init-param greeting='Hello, World'/>
  </web-app>
  
  WEB-INF/web.xml //web.xml不一定有自己新建一个即可,这个是我改过的!
  <web-app>
  <servlet servlet-name='hello-world'
  servlet-class='test.HelloWorld'/> <servlet-mapping url-pattern='/hello'
  servlet-name='hello-world'/>
  </web-app>
  
  原始文档中有三个错误,我也不知道是不是我错了!但是我改过三个错误,运行成功!
  1。servlet servlet-name标签应该放在servlet-mapping前面。
  2。<servlet servlet-name='hello-world' servlet-class='test.HelloWorld'>标签结尾少了一个" / "。
  3。<init-param greeting='Hello, World'/> 这句标签我去掉了,不然也无法运行!
  The Java code, HelloWorld.java belongs in
  
  $app-dir/WEB-INF/classes/test/HelloWorld.java
  
  Or, if you're compiling the servlet yourself, the class file belongs in
  
  $app-dir/WEB-INF/classes/test/HelloWorld.class
  
  Following is the actual servlet code. It just prints a trivial Html page filled with the greeting specified in the web.xml.
  
  init() and destroy() are included mostly for illustration. Resin will call init() when it starts the servlet and destroy before Resin destroys it.
  
  package test;
  
  import java.io.*;
  import javax.servlet.*;
  import javax.servlet.http.*;
  
  public class HelloWorld extends HttpServlet {
  private String greeting;
  
  public void init()
  throws ServletException
  {
  greeting = getInitParameter("greeting");
  }
  
  public void doGet(HttpServletRequest request,
  HttpServletResponse response)
  throws ServletException, IOException
  {
  PrintWriter out = response.getWriter();
  
  out.println("<title>" + greeting + "</title>");
  out.println("<h1>" + greeting + "</h1>");
  }
  
  public void destroy()
  {
  // nothing to do
  }
  }
  
  它文档中的这个用了那个<init-param greeting='Hello, World'/>标签,由于我删除了,所以无法使用!
  就用着吧!保存为HelloWorld.java放在WEB-INF/classes/test目录下面。
  
  package test;
  import java.io.*;
  import java.util.*;
  import javax.servlet.*;
  import javax.servlet.http.*;
  
  public class HelloWorld extends HttpServlet{
  public void doGet(HttpServletRequest req, HttpServletResponse res)
  throws ServletException, IOException
  {
  res.setContentType("text/html");
  PrintWriter pw = res.getWriter();
  pw.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">");
  pw.println("<head>");
  pw.println("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">");
  pw.println("<!-- The Servlet eXPression tags interpolate script variables into the HTML -->");
  pw.println("<title>Hello, world!</title>");
  pw.println("</head>");
  pw.println("<body bgcolor=#cc99dd>");
  pw.println("<h1>Hello, world!</h1>");
  pw.println("</body>");
  pw.close();
  }
  }
  
  开启Resin服务,在浏览器中输入 http://localhost:8080/hello
  即可以正确访问!
上一篇:教您如何解决J2ME开发中的连续按键问题 人气:569
下一篇:Weblogic Server实现EOS负载均衡 人气:756
浏览全部Java的内容 Dreamweaver插件下载 网页广告代码 祝你圣诞节快乐 2009年新年快乐