在刚开始学习SpringMVC的时候,既需要前端的知识,有需要后端的知识,可能出现了一个问题,就会让整个程序无法运行出来,我相信很多同学在根据网上的资料进行学习的时候,笔者提供的思路是正确的,但是他们提供的代码却存在很多问题,所以其中存在任何一个问题,都会导致我们的程序无法运行出来,**今天我在学习SpringMVC通过实体bean接收数据的时候,**发现可程序中存在的三大问题,下面就给出具体的解决方法,希望能给帮助到大家。
(1)注册页面怎么运行都运行不出来
后来经过自己查询问题,终于发现问题了,就是因为以上的一句话,原因很简单,input中需要使用submit提交表单信息,正确的代码如下:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<form action="${pageContext.request.contextPath }/user/register" method="post" name="registForm">
<table border=1 bgcolor="lightblue" align="center">
<tr>
<td>姓名:</td>
<td>
<input class="textSize" type="text" name="uname" value="${uname }" />
</td>
</tr>
<tr>
<td>密码:</td>
<td>
<input class="textSize" type="password" maxlength="20" name="upass" />
</td>
</tr>
<tr>
<td>确认密码:</td>
<td>
<input class="textSize" type="password" maxlength="20" name="reupass" />
</td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" value="注册" onclick="gogo()" />
</td>
</tr>
</tab1e>
</form>
</body>
</html>
所以以上的一句话非常关键,如果写错了,无法提交表单信息,整个通过实体bean接收数据的功能就无法实现。
(2)怎么加载不出来首页*(index)*,如下图界面
原因很简单,就是因为笔者提供的源代码中,controller存在问题,完整的IndexController如下所示
@RequestMapping("/index")
public class IndexController {
/**/@RequestMapping("/loginform")
public String loginForm(){
return "index";
}
@RequestMapping("/login")
public String login() {
return "login"; // 跳转到/WEB-INF/jsp下的login.jsp
}
@RequestMapping("/register")
public String register() {
return "register";
}
}
在程序启动的时候,需要执行
http://localhost:8080/SpringMVCDemo01/user/login
将以上的界面加载寄进来
(3)为什么在登录界面中点击取消按钮,但是没有效果
就是因为login代码中,多加了一个",大家都是知道的,程序中任何地方出现问题,都会导致整个程序运行出现问题,所以,笔者真的是马虎啊,让我们初学者饱受折磨,具体的代码入下所示
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<form action="${pageContext.request.contextPath }/user/login" method="post">
<table>
<tr>
<td colspan="2">
</td>
</tr>
<tr>
<td>姓名:</td>
<td>
<input type="text" name="uname" class="textSize">
</td>
</tr>
<tr>
<td>密码:</td>
<td>
<input type="password" name="upass" class="textsize">
</td>
</tr>
<tr>
<td colspan="2">
<input type="submit" value = "确定" onclick="gogo()">
<input type="submit" value = "取消" onclick="cancel()">
</td>
</tr>
</table>
${messageError }
</form>
</body>
</html>
好了以上就是那篇文章中暴露的问题,希望能够对大家有所帮助。