用jsp怎样做一个用户登录界面
2个回答
展开全部
//jsp文件,登录界面
<%@page pageEncoding="utf-8" contentType="text/html; charset = utf-8"%>
<body>
<h1>Register</h1>
<hr />
<form action="login" method="post">
用户名:
<input type="text" name="username" id="text" />
密 码:
<input type="password" name="pwd" id="text" //>
<input type="submit" value="登录" id="button" />
</form>
</body>
//这是server文件,web.xml部署名字login
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
public class AddUser extends HttpServlet {
public void service(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=utf-8");
request.setCharacterEncoding("utf-8");
String username=request.getParameter("username");
String pwd=request.getParameter("pwd");
try{
if(username.equals("name")&&pwd.equals("pwd") ){
system.out.print("登录成功");
}else{
system.out.print("error");
}
}catch(Exception e){
e.printStackTrace();
}
}
}
简单的登录界面,不需要数据库,如果要链接数据库就要判断很多了
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询