日期:2014-05-18 浏览次数:20654 次
<div class="easyui-panel" title="用户登录" style="width:300px">
<div style="padding:10px 0 0 40px">
<form id="ff" method="post" action="http://localhost:8080/easyui/UserLoginServlet">
<table>
<tr>
<td>
用户:
</td>
<td>
<input class="ww" type="text" name="name"></input>
</td>
</tr>
<tr>
<td>
密码:
</td>
<td>
<input class="ww" type="password" name="password"></input>
</td>
</tr>
</table>
</form>
</div>
<div style="text-align:center;padding:5px">
<a href="javascript:void(0)" class="easyui-linkbutton"
onclick="submitForm()">登录</a>
<a href="javascript:void(0)" class="easyui-linkbutton"
onclick="clearForm()">取消</a>
</div>
</div>
<script>
function submitForm(){
$('#ff').form('submit');
}
function clearForm(){
$('#ff').form('clear');
}
</script>
public class UserLoginServlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
this.doPost(request, response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
String name = request.getParameter("name");
String password = request.getParameter("password");
System.out.println("用户: " + name);
System.out.println("密码: " + password);
if("admin".equals(name) && "123".equals(password)) {
request.getRequestDispatcher("/success.html").forward(request, response);
} else {
response.sendRedirect("http://localhost:8080/easyui/fail.html");
}
}
}
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<servlet>
<servlet-name>UserLoginServlet</servlet-name>
<servlet-class>com.wisher.easyui.servlet.UserLoginServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>UserLoginServlet</servlet-name>
<url-pattern>/UserLoginServlet</url-pattern>
&nbs