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">
(
首页
用户名: |
|
密 码: |
|
|
)
登录失败页面(成功页面和这个只有汉字有点差异):
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
登录失败
登录失败
${message }
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">