当我尝试访问某些jsp文件时,它会给我错误

时间:2017-05-21 02:18:53

标签: java spring jsp

这里是我的代码:

register.jsp

<body>
 <div> 
 <h3>Register</h3> 
 <form:form method="post" action="insert" modelAttribute="user">  
 <table>  
 <tr>  
  <td>User Name :</td>  
  <td><form:input path="uName" /></td>  
 </tr>  
 <tr>  
  <td>Password :</td>  
  <td><form:input path="password" /></td>  
 </tr>  
 <tr>  
  <td> </td>  
  <td><input type="submit" value="Save" /></td>  
 </tr>  
 </table>
 </form:form>
 </div>
 <div>  
 <h3>Login</h3>
 <form:form method="post" action="login" modelAttribute="user">  
 <table>  
 <tr>  
  <td>User Name :</td>  
  <td><form:input path="uName" /></td>  
 </tr>  
 <tr>  
  <td>Password :</td>  
  <td><form:input path="password" /></td>  
 </tr>  
 <tr>  
  <td> </td>  
  <td><input type="submit" value="Submit" /></td>  
 </tr>  
 </table>
 </form:form>
 </div>

 </body>

HomePageController.java

@Controller
public class HomePageController {

@Autowired
UserDaoImpl userDaoImpl;
@RequestMapping("/register")
public ModelAndView registerUser(@ModelAttribute user use){
    return new ModelAndView("register");

}
@RequestMapping("/insert")
public ModelAndView successMessage(@ModelAttribute user use){
    if(use != null){
        userDaoImpl.insertData(use);
    }
    return new ModelAndView("success" ,"name", use.getuName());
}
@RequestMapping("/login")
public ModelAndView getUserList(@ModelAttribute user u){
    List<user> userList = userDaoImpl.getData();
    int len = userList.size();
    for(int i = 0;i<= len ; i++){
        String userr = userList.get(i).getuName();
        if(userr.equals(u.getuName())){
            return new ModelAndView("quiz","name", u.getuName());
        }
    }
    return new ModelAndView("register");
}
@RequestMapping("/userSign")
public ModelAndView getUser(String name){

    List<user> userList = userDaoImpl.getData();
    int len = userList.size();
    for(int i = 0;i<= len ; i++){
        String userr = userList.get(i).getuName();
        if(userr.equals(name)){
            return new ModelAndView("quiz","name", name);
        }
    }
    return new ModelAndView("error","name",name);
 }
}

在登录表单中,如果我输入了正确的用户名和密码,那么它会成功显示quiz.jsp文件,但是如果我输入了错误的用户名和密码,那么它必须显示error.jsp,但它不会显示error 404: requested resource not found spring-servlet.xml <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"> <!-- telling container to take care of annotations stuff --> <context:annotation-config /> <context:component-scan base-package="com.quiz"></context:component-scan> <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/jsp/"/> <property name="suffix" value=".jsp"/> </bean> <bean id="user" class="com.quiz.model.user"></bean> <bean id="userDaoImpl" class="com.quiz.dao.UserDaoImpl"></bean> <!-- declare datasource bean --> <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName" value="com.mysql.jdbc.Driver" /> <property name="url" value="jdbc:mysql://localhost:3306/quiz" /> <property name="username" value="root" /> <property name="password" value="root" /> </bean> </beans> web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"> <display-name>QUIZ</display-name> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> <servlet> <servlet-name>spring</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet- class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>spring</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> </web-app>

HTTP Status 500 - Request processing failed; nested exception is 
java.lang.IndexOutOfBoundsException: Index: 9, Size: 9


type Exception report

message Request processing failed; nested exception is 
java.lang.IndexOutOfBoundsException: Index: 9, Size: 9

description The server encountered an internal error that prevented it from 
fulfilling this request.

exception 
org.springframework.web.util.NestedServletException: Request processing 
failed; nested exception is java.lang.IndexOutOfBoundsException: Index: 9,  
Size: 9
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkSer
vlet.java:982)
org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.jav
a:872)
javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.ja
va:846)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)


root cause
java.lang.IndexOutOfBoundsException: Index: 9, Size: 9
java.util.ArrayList.rangeCheck(Unknown Source)
java.util.ArrayList.get(Unknown Source)
com.quiz.controller.HomePageController.getUserList(HomePageController.java:3
8)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
java.lang.reflect.Method.invoke(Unknown Source)
org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeH
andlerMethod(HandlerMethodInvoker.java:180)
org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapte
r.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:440)
org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapte
r.handle(AnnotationMethodHandlerAdapter.java:428)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServl
et.java:963)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServle
t.java:897)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkSer
vlet.java:970)
org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.jav
a:872)
javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.ja
va:846)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)


note The full stack trace of the root cause is available in the Apache 
Tomcat/8.0.29 logs.

这就是错误

quiz.jsp

我再次在play.jsp中有一个链接,如果我点击该链接,那么它必须转到<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>play quiz</title> </head> <body> Welcome ${name} <a href="play.jsp">Play quiz</a> </body> </html> ,但它正在向我提供错误请求的资源未找到

def power(a,b):
    if b == 0:
      return 1
    else:
      return eval(((str(a)+"*")*b)[:-1])

1 个答案:

答案 0 :(得分:0)

你的for循环中你的范围检查是错误的。

他们都需要&#39;&lt;&#39;不是&#39;&lt; =&#39;