仅在单击提交按钮后显示注册页面显示错误
http status 404
request source is not available
jsp页面是:
<div>
<form:form method="post" action="/log" modelAttribute="user">
<table>
<tr>
<td>Task id :</td>
<td><input type="text" name="id"></td>
</tr>
<tr>
<td><input type="submit" value="Save" /></td>
</tr>
</table>
</form:form>
</div>
控制器页面是:
{ public class HomePageController
{@Autowired
UserService userService;
@RequestMapping(value="/log",method=RequestMethod.POST)
public ModelAndView getUserLIst(@RequestParams("id")String id @ModelAttribute User user)
{
List<User> userList = userService.getUserList(id);
return new ModelAndView("userList", "userList", userList);
}
的web.xml:
<display-name>SpringDatabase</display-name>
<welcome-file-list>
<welcome-file>register.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>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
spring.xml是:
<!-- telling container to take care of annotations stuff -->
<context:annotation-config />
<mvc:default-servlet-handler/>
<!-- declaring base package -->
<context:component-scan base-package="default-package" />
<!-- adding view resolver to show jsp's on browser -->
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
<!-- declare beans -->
<bean id="userDao" class="UserDaoImpl" />
<bean id="userService" class="UserServiceImpl" />
<!-- 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/eximat" />
<property name="username" value="root" />
<property name="password" value="mysql" />
</bean>
userlist.jsp是:
table border="1">
<tr>
<td class="heading">User Id</td>
<td class="heading">First Name</td>
<td class="heading">Last Name</td>
<td class="heading">Gender</td>
<td class="heading">City</td>
</tr>
<c:forEach var="user" items="${userList}">
<tr>
<td>${user.userId}</td>
<td>${user.firstName}</td>
<td>${user.lastName}</td>
<td>${user.gender}</td>
<td>${user.city}</td>
</tr>
</c:forEach>
</table>
答案 0 :(得分:0)
use this
<div>
<form:form method="post" action="log" modelAttribute="user">
<table>
<tr>
<td>Task id :</td>
<td><input type="text" name="id"></td>
</tr>
<tr>
<td><input type="submit" value="Save" /></td>
</tr>
</table>
</form:form>
</div>
答案 1 :(得分:0)
请检查您的jsp文件的URL,因为这可能是导致404错误的唯一原因。由于http未在URL中获取请求的资源,因此您的网址存在一些错误。