81,095
社区成员
发帖
与我相关
我的任务
分享
package test;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class SetContextPath extends HttpServlet
{
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException
{
// TODO Auto-generated method stub
service(req, resp);
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException
{
// TODO Auto-generated method stub
service(req, resp);
}
@Override
protected void service(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException
{
String contentPath = request.getContextPath();
String realPath = request.getRealPath("/");
//TODO: 调用你的类设置 如
//Sysinfo.setContentPath(contentPath);
//Sysinfo.setRealPath(realPath);
super.service(request, response);
}
}
<servlet>
<servlet-name>SetContextPath</servlet-name>
<servlet-class>test.SetContextPath</servlet-class>
<load-on-startup>0</load-on-startup>
</servlet>
package test;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class SetContextPath extends HttpServlet
{
public static A a;
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException
{
// TODO Auto-generated method stub
service(req, resp);
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException
{
// TODO Auto-generated method stub
service(req, resp);
}
@Override
protected void service(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException
{
String contentPath = request.getContextPath();
String realPath = request.getRealPath("/");
a.setProjectName(contentPath);
super.service(request, response);
}
@Override
public void init() throws ServletException
{
a=new A();
super.init();
}
}