展开全部
首先用vi编写一个linux.java的文件.
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class HelloLinux extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head>");
out.println("<title>Hello Linux World!</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>Hello Linux World!</h1>");
out.println("</body>");
out.println("</html>");
}
}
保存退出后在环境变量里添加: vi /wtc/profile
export CLASSPATH=$CLASSPATH:/usr/local/jakarta-tomcat-5.5.9/common/lib/servlet-api.jar
保存退出后.
编译hellolinux.java 生成hellolinux.class.
mv hellolinux.* /usr/local/jakarta-tomcat-5.5.9/webapps/servlet-examplets/WEB-INF/classes
然后编辑 vi /usr/local/jakarta-tomcat-5.5.9/webapps/servlet-examplets/WEB-INF/web.xml
在其中添加如下代码:
<servlet>
<servlet-name>hellolinux</servlet-name>
<servlet-class>hellolinux</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>hellolinux</servlet-name>
<url-pattern>/servlet/hellolinux</url-pattern>
</servlet-mapping>
然后在linux下就可以测试了或是在windows下测试:
http://IP/servlets-examples/servlet/hellolinux
就可以看到用JSP打印的一个网页.
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class HelloLinux extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head>");
out.println("<title>Hello Linux World!</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>Hello Linux World!</h1>");
out.println("</body>");
out.println("</html>");
}
}
保存退出后在环境变量里添加: vi /wtc/profile
export CLASSPATH=$CLASSPATH:/usr/local/jakarta-tomcat-5.5.9/common/lib/servlet-api.jar
保存退出后.
编译hellolinux.java 生成hellolinux.class.
mv hellolinux.* /usr/local/jakarta-tomcat-5.5.9/webapps/servlet-examplets/WEB-INF/classes
然后编辑 vi /usr/local/jakarta-tomcat-5.5.9/webapps/servlet-examplets/WEB-INF/web.xml
在其中添加如下代码:
<servlet>
<servlet-name>hellolinux</servlet-name>
<servlet-class>hellolinux</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>hellolinux</servlet-name>
<url-pattern>/servlet/hellolinux</url-pattern>
</servlet-mapping>
然后在linux下就可以测试了或是在windows下测试:
http://IP/servlets-examples/servlet/hellolinux
就可以看到用JSP打印的一个网页.
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询