Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1443064
  • 博文数量: 3500
  • 博客积分: 6000
  • 博客等级: 准将
  • 技术积分: 43870
  • 用 户 组: 普通用户
  • 注册时间: 2008-05-03 20:31
文章分类

全部博文(3500)

文章存档

2008年(3500)

我的朋友

分类:

2008-05-04 23:41:14

一起学习

 



1. Write the JSP

Example (uno.jsp) :





<%@ page import="java.text.*,

java.util.*"%>



<HTML>

<BODY>

<%

Date d = new Date();

String hoy = DateFormat.getDateInstance().format(d);

%>

La Fecha de hoy es :

<EM> <%= hoy %> </EM>

</BODY>

</HTML>



2. Create a WAR file with JSP file. Use the following command :



jar -cvfM uno.war uno.jsp





3. Create an application.xml file in META-INF directory. You need set the correct values in  tag and  tag.



web-uri = WAR name file



Example (application.xml):





<?xml version="1.0" encoding="ISO-8859-1"?>

<application>

<display-name>uno</display-name>

<module>

<web>

<web-uri>uno.war</web-uri>

<context-root>/uno</context-root>

</web>

</module>

</application>



4. Create a EAR file with WAR file and application.xml file. Use the following command :



jar -cvfM uno.ear uno.war META-INF



5. Copy this EAR file in %JBOSS_HOME%\server\default\deploy



6. Run the JBoss-Tomcat server.



7. Test the JSP. Use the following URL:



http://[IP ADDRESS SERVER]:8080/uno/uno.jsp



The first time is slow because JBoss-Tomcat compiles the JSP file but the next time is fast.





HERE IS THE PROCEDURE FOR SERVLETS :





1. Write your servlet. For example



Dos.java



package com.servlet;



import java.io.*;

import javax.servlet.*;

import javax.servlet.http.*;



public class Dos extends HttpServlet {

public void doGet(HttpServletRequest request,

HttpServletResponse response)

throws ServletException, IOException {



PrintWriter out = response.getWriter();

out.println("Hello World");

}

}



2. Compile your servlet. Use the following command :



javac -classpath d:\jboss-3.0.1_Tomcat-4.0.4\catalina\common\lib\servlet.jar Dos.java



3. Create a WEB-INF directory.



4. Create a classes directory in WEB-INF directory and copy Dos.class.





WEB-INF (Subdirectory)

I

I

classes (Subdirectory) --- 

I

I

com (subdirectory)----

I

I

servlet (subdirectory)

I

I

Dos.class (Java Class)



5. Create a web.xml file in WEB-INF directory.



For example:



<?xml version="1.0" encoding="ISO-8859-1"?>



<!DOCTYPE web-app

PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"

"">

<web-app>

<servlet>

<servlet-name>Dos</servlet-name>

<servlet-class>com.servlet.Dos</servlet-class>

</servlet>

</web-app>



6. Create a META-INF directory.



7. Create an application.xml file in META-INF directory.



For example:



application.xml



<?xml version="1.0" encoding="ISO-8859-1"?>

<application>

<display-name>dos</display-name>

<module>

<web>

<web-uri>dos.war</web-uri>

<context-root>/dos</context-root>

</web>

</module>

</application>



8. Create a WAR file. Use the following command :



jar -cvfM dos.war WEB-INF



9. Create a EAR file. Use the following command :



jar -cvfM dos.ear dos.war META-INF



10. Copy the EAR file in %JBOSS_HOME%\server\default\deploy



11. Run the JBoss-Tomcat server.



12. Test the Servlet. Use the following URL:



http://[IP ADDRESS SERVER]:8080/dos/servlet/Dos



下载本文示例代码


jboss下的简单JSP与SERVLET应用部属jboss下的简单JSP与SERVLET应用部属jboss下的简单JSP与SERVLET应用部属jboss下的简单JSP与SERVLET应用部属jboss下的简单JSP与SERVLET应用部属jboss下的简单JSP与SERVLET应用部属jboss下的简单JSP与SERVLET应用部属jboss下的简单JSP与SERVLET应用部属jboss下的简单JSP与SERVLET应用部属jboss下的简单JSP与SERVLET应用部属jboss下的简单JSP与SERVLET应用部属jboss下的简单JSP与SERVLET应用部属
阅读(228) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~