JavaWeb 项目-课程表信息的添加
in inboxJavaWeb with 0 comment

JavaWeb 项目-课程表信息的添加

in inboxJavaWeb with 0 comment

设计思想
输入信息之后可以对其进行核查
如果符合要求那么对其进行添加
如果不符合要求直接跳转回页面要求重新输入
程序源代码
NewFile.jsp

<%@ 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>
<title>添加</title>
</head>
<body>
    <form action="addcheck.jsp" method="get">
    <table align="center" border="1" width="500">
        <tr>
            <td>课程名称:</td>
            <td>
            <input type="text" name="name"/>
            </td>
        </tr> 
        <tr>
            <td>上课地点:</td>
            <td>
            <input type="text" name="location">
            </td>
        </tr>
        <tr>
            <td>老师姓名:</td>
            <td>
            <input type="text" name="teacher">
            </td>
        </tr>
        <tr align="center">
            <td colspan="2">
            <input type="submit" value="增加"  />
        </td>
        
        </tr>
</table>
</form>


</body>
</html>

addcheck.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@page import="P.User"%>
<%@page import="P.UserUtil"%>
<!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>

<% 
    String name=request.getParameter("name");
    String location=request.getParameter("location");
    String teacher=request.getParameter("teacher");
    out.print(teacher);

    if(name == null || "".equals(name.trim())){
        request.setAttribute("error", "用户名不能为空");
        %>
        
<%     }
    else{
%>

<% 
    User u=new User();
    u.name=name;
    u.location=location;
    u.teacher=teacher;
    if(UserUtil.check(u)){
        UserUtil.add(u);
        %>    
        <script type="text/javascript" language="javascript">
        alert("保存成功");
    </script>    
<%    
    }else
    {
%>    
        <script type="text/javascript" language="javascript">
        alert("输入有误");
        window.document.location.href="NewFile.jsp";
    </script>    
    <%    
        
    }
    }
%>



</body>
</html>

程序运行截图
11.jpg

2.jpg

3.jpg

Responses