正在回答
5回答
建议同学新建一个空的JavaWeb项目,发布到Tomcat9后试一下,看是否可以启动成功;如果可以启动成功,说明Tomcat服务器没有问题,是当前发布的项目配置文件存在问题,此时同学可以把项目结构和配置文件帖一下;如果不可以启动成功,建议重新下载Tomcat后再试下~
祝学习愉快!
WindBelll
2019-01-01 17:45:15
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1"> <display-name>LibraryManageSystem</display-name> <welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file>index.htm</welcome-file> <welcome-file>index.jsp</welcome-file> <welcome-file>default.html</welcome-file> <welcome-file>default.htm</welcome-file> <welcome-file>default.jsp</welcome-file> </welcome-file-list> <servlet> <servlet-name>init</servlet-name> <servlet-class>com.cl.servlet.InitServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>init</servlet-name> <url-pattern>/InitServlet</url-pattern> </servlet-mapping> <filter> <filter-name>encoding</filter-name> <filter-class>com.cl.filter.EncodingFilter</filter-class> <init-param> <param-name>charset</param-name> <param-value>UTF-8</param-value> </init-param> </filter> <filter-mapping> <filter-name>encoding</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> </web-app> //初始化的servlet代码如下 package com.cl.servlet; import java.util.ArrayList; import java.util.List; import javax.servlet.ServletConfig; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import com.cl.domain.User; /** * Servlet implementation class InitServlet */ public class InitServlet extends HttpServlet { private static final long serialVersionUID = 1L; public void init(ServletConfig config) throws ServletException { // TODO Auto-generated method stub List<User> list=new ArrayList<User>(); this.getServletContext().setAttribute("userMsg", list); } } //sesssionFilter,不知到是不是这个的原因 package com.cl.filter; import java.io.IOException; import javax.servlet.Filter; import javax.servlet.FilterChain; import javax.servlet.FilterConfig; import javax.servlet.ServletException; import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; import javax.servlet.annotation.WebFilter; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @WebFilter(urlPatterns= {"server.jsp","addBook.jsp","catgory.jsp","showBooks.jsp","top.jsp"}) public class LoginFilter implements Filter { @Override public void destroy() { // TODO Auto-generated method stub } @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { System.out.println("<----LoginFilte----->"); HttpServletRequest hrequest=(HttpServletRequest)request; HttpServletResponse hresponse=(HttpServletResponse)response; String username=(String)hrequest.getSession().getAttribute("user"); //String uri=hrequest.getRequestURI(); //System.out.println(uri); if(username==null||username=="") { hresponse.sendRedirect(hrequest.getContextPath()+"/index.jsp?flag=1"); }else { chain.doFilter(request, response); return; } } @Override public void init(FilterConfig filterConfig) throws ServletException { // TODO Auto-generated method stub } }
从网页搭建入门Java Web2018版
- 参与学习 人
- 提交作业 1088 份
- 解答问题 10205 个
如果你有Java语言基础,又想以后从事Java Web开发,那么本路径是你的不二选择!本路径从网页搭建开始入手,通过大量案例来学习Java Web基础。定能助你完成Java Web小白的蜕变!
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星