tomcat啟動正常了,訪問首頁面也成功,可是我從首頁面跳轉到其他頁面怎麼會報”404“啊?剛開始學習這個,不太懂,請高人解答?
網頁錯誤信息如下:
HTTP Status 404 -
type Status report
message
description The requested resource is not available.
Apache Tomcat/8.0.9
頁面配置如下:
首頁:
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
(
controller類文件內容:
public class Logincontroller implements Controller{
private Loginservice ls;
public Loginservice getLs() {
return ls;
}
public void setLs(Loginservice ls) {
this.ls = ls;
}
@Override
public ModelAndView handleRequest(HttpServletRequest arg0,
HttpServletResponse arg1) throws Exception {
// TODO Auto-generated method stub
String username=arg0.getParameter("username");
String password=arg0.getParameter("password");
boolean flag=ls.login(username, password);
ModelAndView mv=new ModelAndView();
if(flag){
//往ModelAndView添加共享變量
mv.addObject("message", "恭喜,你贏啦!");
//設置響應的視圖名字
mv.setViewName("success");
}else {
mv.addObject("messege", "抱歉,認證失敗");
mv.setViewName("fail");
}
return mv;
}
}
public class Accountcontroller implements Controller{
@Override
public ModelAndView handleRequest(HttpServletRequest arg0,
HttpServletResponse arg1) throws Exception {
ModelAndView mav=new ModelAndView();
mav.setViewName("success");
return mav;
}
}
service類文件內容:
public class Loginservice {
public boolean login(String username,String password){
boolean flase=false;
if(username.equals("admin")&&password.equals("admin")){
flase=true;
}
return flase;
}
}
web.xml文件內容:
<?xml version="1.0" encoding="UTF-8"?>
spring_mvc
springmvc
org.springframework.web.servlet.DispatcherServlet
<!-- 加載springmvc的配置文件 -->
contextConfigLocation
classpath:springmvc.xml
1
springmvc
*.htm
index.html
index.htm
index.jsp
default.html
default.htm
default.jsp
spring的xml文件內容如下:
<?xml version="1.0" encoding="UTF-8"?>
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd">
此問題稀裡糊塗的沒有了,應該是tomcat的裡邊的緩存問題吧。