日期:2014-05-20 浏览次数:20925 次
package com.nong; import java.io.*; import java.sql.*; import javax.servlet.*; import javax.servlet.http.*; public class CreateDBServlet extends HttpServlet{ private String url; private String user; private String password; String driverClass; String s1; public void init() throws ServletException { s1=this.getInitParameter("servletParam"); } public void doGet(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException { res.setContentType("text/html"); PrintWriter out = res.getWriter(); String s2 = getServletContext().getInitParameter("webParam"); out.println("s1"+s1); out.println("<br>"); out.println("s2"+s2); out.flush(); out.close(); } public void doPost(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException { this.doGet(req,res); } }
<?xml version="1.0" encoding="UTF-8"?> <web-app id="WebApp_ID" version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <context-param> <param-name>webParam</param-name> <param-value>aaa</param-value> </context-param> <servlet> <servlet-name>test</servlet-name> <servlet-class>Test</servlet-class> </servlet> <init-param> <param-name>servletParam</param-name> <param-value>bbb</param-value> </init-param> <servlet-mapping> <servlet-name>test</servlet-name> <url-pattern>/test</url-pattern> </servlet-mapping> <servlet> <servlet-name>my</servlet-name> <servlet-class>com.nong.CreateDBServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>my</servlet-name> <url-pattern>/my</url-pattern> </servlet-mapping> </web-app>