成功.jsp:
<h5>Login Successful</h5> Welcome to : <h4><%= request.getParameter("login_uname")%></h4>
制定形式?
回答:
学生表:
create table student ( stno number (3), stname varchar2 (15), college varchar2 (20), marks number (5,2), dob date ); /
login.html:
<html> <body> <center> <form name="login" action="security.jsp" method="post"> <table> <tr> <th align="left">Enter username : </th> <td><input type="text" name="login_uname" value=""></td> </tr> <tr> <th align="left">Enter password : </th> <td><input type="password" name="login_pwd" value=""></td> </tr> </table> <input type="submit" value="Login"> <input type="reset" value="Clear"> </form> </center> </body> </html>
first.jsp:
<%@ page session="true" %> <html> <body> <center> <form name="first" action="second.jsp" method="post"> <table> <tr> <th align="left">Enter number : </th> <td><input type="text" name="first_stno" value=""></td> </tr> <tr> <th align="left">Enter name : </th> <td><input type="text" name="first_stname" value=""></td> </tr> </table> <input type="submit" value="Send"> <input type="reset" value="Clear"> </form> </center> </body> </html>
标准操作:
这些基本上用于将运行时信息传递给容器。
作为JSP的一部分,我们有以下标准操作;它们是<JSP:forward/>, <JSP:include/>, <JSP:param/>, <JSP:useBean/>, <JSP:setProperty/> 和 <JSP:getProperty>.
- <JSP:forward/>:当我们要从源JSP中转发到目标JSP页面的请求和响应时,我们必须使用<JSP:Forward>。
语法:
不带主体
<JSP:forward page="relative or absolute path of JSP page"/>
带主体:
<JSP:forward page=" relative or absolute path of JSP page"> <JSP:param name="param name1" value="param value1"/> <JSP:param name="param name2" value="param value2"/> </JSP:forward>
例如:
<JSP:forward page="y.jsp"> <JSP:param name="v1" value="10" <JSP:param name="v2" value="20" </JSP:forward>
当我们使用此标记时,我们只能获得目的地JSP页面的响应但不是源JSP页面。
- <JSP:包含:此标记用于通过包括其他JSP页面和HTML等静态资源来处理源JSP页面的客户端请求。一个源JSP可以包括'n'服务器侧资源,最后我们仅获得源JSP的响应。语法:没有身体:
<JSP:include page="relative or absolute path of JSP page"
与身体:
<JSP:include page=" relative or absolute path of JSP page"> <JSP:param name="param name1" value="param value1" <JSP:param name="param name2" value="param value2" </JSP:include>
例如 - 1:
<JSP:include page="y.jsp"> <JSP:param name="v1" value="10" <JSP:param name="v2" value="20" </JSP:include>
例如 - 2:
<JSP:include page="z.jsp"> <JSP:param name="v3" value="30" <JSP:param name="v4" value="40" </JSP:include>
- <JSP:PARAM :此标记用于以(键,值)对的形式将一个JSP页面的本地数据传递给另一个JSP页面。
Syntax:
<jsp:param name ="参数的名称"值="参数的值"此处,名称表示参数或者属性的名称,它必须是唯一值表示参数的值,应该是始终字符串。 <JSP:PARAM 标签应与<JSP:FORCORE OR或者<JSP:INCLUDE INCLUDE 连接使用。例如 - 1:
<JSP:forward page="y.jsp"> <JSP:param name="v1" value="10" <JSP:param name="v2" value="20" </JSP:forward>
例如 - 2:
<JSP:include page="y.jsp"> <JSP:param name="v1" value="10" <JSP:param name="v2" value="20" </JSP:include>
例如 - 3:
<JSP:include page="z.jsp"> <JSP:param name="v3" value="30" <JSP:param name="v4" value="40" </JSP:include>
编写一个JSP页面,说明<jsp:forward 和<jsp:cround 的概念?
回答:
login.html:
<html> <head><center><h3>Login Page</h3></center></head> <body> <center> <h4>Forward/Include test</h4> <form name="login" action="Login.jsp" method="post"> <p>Enter username : <input type="text" name="login_uname" value=""><br> Enter password : <input type="password" name="login_pwd" value=""><br> <input type="submit" value="Login"> </form> </center> </body> </html>
third.jsp:
<%@ page session="true" %> <%@ page import="java.sql.*, java.io.*" %> <html> <%! Connection con = null; PreparedStatement ps = null; public void jspInit() { try { Class.forName("oracle.jdbc.driver.OracleDriver"); con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:Hanuman", "scott", "tiger"); ps = con.prepareStatement("insert into student values (?, ?,?, ?,?)"); } catch (Exception e) { out.println(e); } }%> <% String stno = request.getParameter("first_stno"); String name = request.getParameter("first_stname"); String college = request.getParameter("second_cname"); String marks1 = request.getParameter("second_marks"); String dob1 = request.getParameter("second_dob"); int number = Integer.parseInt(stno); float marks = Float.parseFloat(marks1); Date dob = Date.parseDate(dob1); %> <%! try { ps.setInt(1, number); ps.setString(2, name); ps.setString(3, college); ps.setFloat(4, marks); ps.setDate(5, dob); int i = ps.executeUpdate(); if (i > 0) {%> <html> <body bgcolor="lightblue"> <center> <h3>Inserted Successfully</h3> </center> <a href="login.html">One more</a> </body> </html> <% } else { %> <html> <body bgcolor="lightblue"> <center> <h3>Try again</h3> </center> <a href="login.html">Home</a> </body> </html> <% } } catch (exception e) { out.println(e); }%> </html>
login.jsp:
<% String s1 = request.getParameter("login_uname"); String s2 = request.getParameter("login_pwd"); if (s1.equals("kalpana") && s2.equals("test")) {%> <JSP:forward page="Success.jsp" <% } else {%> <h5>Login failed</h5> <JSP:include page="Login.html" <% }%>
second.jsp:
<%@ page session="true" %> <html> <body> <center> <form name="second" action="third.jsp" method="post"> <table> <tr> <th align="left">Enter college name : </th> <td><input type="text" name="second_cname" value=""></td> </tr> <tr> <th align="left">Enter marks : </th> <td><input type="text" name="second_marks" value=""></td> </tr> <tr> <th align="left">Enter date of birth : </th> <td><input type="text" name="second_dob" value=""></td> </tr> </table> <input type="submit" value="Send"> <input type="reset" value="Clear"> </form> </center> </body> </html>
web.xml:
<web-app> </web-app>
web.xml:
<web-app> </web-app>
security.jsp:
<%@ page session="true" %> <html> <% String s1 = request.getParameter("login_uname"); String s2 = request.getParameter("login_pwd"); if (s1.equals("student") && s2.equals("test")) {%> <JSP:forward page="first.jsp" <% } else {%> <h4>Login Failed</h4> <JSP:include page="login.html" <% }%> </html>
日期:2020-04-11 23:04:39 来源:oir作者:oir