我要想在login.jsp的代码执行之前做一些工作,比如说,读配置文件,创建连接池,建立连接,写日志文件等等,这些事情都不是通过login.jsp中的代码调用的,而是在显示login.jsp之前做的,请问能否实现
解决方案 »
- 有个按钮,每次点击都添加1个新的select元素和2个input。怎么写js当新增加的select改变时,其中一个input的值也改变?
- iframe如何设置焦点不移出iframe窗口
- 菜鸟有关jsp方面的问题请前辈们指导。
- 初学JSP的一些疑问,现在JSP一般是使用那种结构来开发WEB啊?
- 请问在myeclipse database explorer中如何连到sqlserver?
- [JSP]数据库中的字符是乱码,why?
- Jsp session 过期时间失效
- 谁知道JBuilder X的注册码是什么?
- jsp 简单问题
- 求助,jsp和javaBean的问题
- user cannot be resolved to a type 这是否是没有把user类加进来啊?
- JSP开发文件上传程式--文件名中文时出错
顶顶顶。
而不显示内容只有业务逻辑(调用JAVABEAN)
public void doGet or doPost(HttpServletRequest arg0, HttpServletResponse arg1)
throws ServletException, IOException
{
**************你要实现的内容
}
然后在转到login.jsp(这个我认为LZ不可能不会)
用
RequestDispatcher requestDispatcher = request.getRequestDispatcher("/login.jsp");
requestDispatcher.forward(request,response);
或者直接用response.sendRedirect(request.getContextPath()+"/login.jsp");
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import java.io.IOException;import com.util.ReadConfigEngine;//读取配置文件的类,根据你的需要自己实现
import com.util.LogEngine; //记录日志的类,根据你的需要自己实现
//还有其他功能,自己添加实现
/**
*
* 该servlet随系统的启动而自己加载,自动启动一些系统的服务
*/
public class StartService implements Servlet {
private ReadConfigEngine CONFIG_ENGINE = null;
private LogEngine LOG_ENGINE = null; public StartService() {
}
public void init(ServletConfig parm1) throws javax.servlet.ServletException {
try {
CONFIG_ENGINE = new ReadConfigEngine();
LOG_ENGINE = new LogEngine(); System.out.println("Starting ReadConfigFile Engine");
CONFIG_ENGINE.start();
System.out.println("ReadConfigFile Engine Started"); System.out.println("Starting Log Engine");
LOG_ENGINE.start();
System.out.println("Auction Log Started");
} catch (Exception e) {
}
}
public ServletConfig getServletConfig() {
/**@todo Implement this javax.servlet.Servlet method*/
throw new java.lang.UnsupportedOperationException("Method getServletConfig() not yet implemented.");
}
public void service(ServletRequest parm1, ServletResponse parm2) throws javax.servlet.ServletException, java.io.IOException {
try {
System.out.println("Starting ReadConfigFile Engine");
CONFIG_ENGINE.start();
System.out.println("ReadConfigFile Engine Started"); System.out.println("Starting Log Engine");
LOG_ENGINE.start();
System.out.println("Auction Log Started");
} catch (Exception e) {
}
}
public String getServletInfo() {
/**@todo Implement this javax.servlet.Servlet method*/
throw new java.lang.UnsupportedOperationException("Method getServletInfo() not yet implemented.");
}
public void destroy() {
try {
CONFIG_ENGINE.stop();
LOG_ENGINE.stop(); CONFIG_ENGINE = null;
LOG_ENGINE = null;
}catch (Exception e) { }
}}在web.xml文件中加入如下配置:
<servlet>
<servlet-name>StartPTCService</servlet-name>
<servlet-class>com.util.servlet.StartService</servlet-class>
<load-on-startup>3</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>StartService</servlet-name>
<url-pattern>/StartService</url-pattern>
</servlet-mapping>
你可以设置为随服务器启动的