⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 computeservlet.java

📁 功能完善的java开发框架
💻 JAVA
字号:
/*
 * Copyright 2003-2005 the original author or authors.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 */
package test;

import java.io.IOException;
import java.io.PrintWriter;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet Class
 *
 * @web.servlet              name="Compute"
 *                           display-name="Name for Compute"
 *                           description="Description for Compute"
 * @web.servlet-mapping      url-pattern="/Compute"
 * @web.servlet-init-param   name="A parameter"
 *                           value="A value"
 * 
 * if you use jdonframework ,you will not need add this tags.
 * 
 * @web.ejb-local-ref name = "ejb/MySessionLocal" home = "test.MySessionLocalHome"
 *      local = "test.MySessionLocal"  type = "session"
 * 
 * @jboss.ejb-local-ref ref-name = "MySessionLocal" jndi-name = "ejb/MySession"  
 *          
 *                    
 */
public class ComputeServlet extends HttpServlet {

    /**
     * 
     */
    public ComputeServlet() {
        super();
        // TODO Auto-generated constructor stub
    }
    
    MySessionLocalHome home;

    public void init(ServletConfig config) throws ServletException {
        super.init(config);
        try {
        		Context context = new InitialContext();
        		home = (MySessionLocalHome)context.lookup("java:comp/env/ejb/MySessionLocal");
        	} catch (Exception e) {
        		throw new ServletException("Lookup of java:/comp/env/ failed");
        	}

    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        

          	response.setContentType("text/html");
          	PrintWriter out = response.getWriter();

          	out.println("<html><head><title>");
          	out.println("Fibonaci Computation");
          	out.println("</title></head>");
          	out.println("<body>");

          	out.println("<h1>");
          	out.println("Fibonaci Computation");
          	out.println("</h1>");

          	try {
          	  MySessionLocal bean = home.create();
          		int limit = 0;
          		String value = request.getParameter("limit");
          		if (value != null) {
          			try {
          				limit = Integer.parseInt(value);
          			} catch (Exception e) {
          			}
          		}
          	 	Integer res = bean.count(limit);
          	  out.println("res=" + res);
          	} catch (Exception e) {
          		out.println(e.getMessage());
          		e.printStackTrace(out);
          	} finally {
          		out.println("</body></html>");
          		out.close();
          	}

    }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -