registerservlet.jsp
来自「weblogic应用全实例」· JSP 代码 · 共 285 行
JSP
285 行
<%
/*
* 这个JSP文件演示一个University HTML客户端怎样使用servlet,
* 调用WebLogic Enterprise University CORBA 对象.
*/
%>
<%//引入其它类或包%>
<%@ page import="
com.beasys.Tobj.*,
com.beasys.*,
UniversityT.RegistrarFactory,
UniversityT.RegistrarFactoryHelper,
UniversityT.Registrar
"%>
<%!
//声明变量
org.omg.CosTransactions.Current TransCur;
boolean validId = true;
%>
<%
UniversityHelper univHelper= new UniversityHelper();
// 获取学生Id和课程号
String courseNum = (String) request.getParameter("COURSE_NUM");
String studentId = (String) request.getParameter("STUDENT_ID");
try {
// 从连接池中获取连接
univHelper.univInit();
TransCur = univHelper.getTransCur();
validId = univHelper.verifyStudent(studentId);
}
catch(Exception e)
{
//有异常抛出,生成错误页面返回
%>
<html>
<head><title>Register For Course - Error</title></head>
<body bgcolor=#FFFFFF>
<font face="Helvetica">
<center>
<h3> <font color='#FF0000'>
Unexpected Error: <%=e.toString()%>
</font> </h3>
<form>
<input type='button' value='Back' OnClick='history.go(-1)'>
</form>
</center>
</font>
</body>
</html>
<%
return;
}
//Id无效
if (validId == false)
{
//生成错误页面,返回
%>
<html>
<head><title>Register For Course - Application Error</title></head>
<body bgcolor=#FFFFFF>
<font face="Helvetica">
<center>
<h3>
<font color='#FF0000'>
Application Error
</font>
</h3>
<table border=0>
<tr>
<td align=right><b>Student Id</b></td>
<td><font color='#0000FF'>
<%=
request.getParameter("STUDENT_ID")
%>
</font></td>
</tr>
</table>
<form>
<input type='button' value='Back' OnClick='history.go(-1)'>
</form>
</center>
</font>
</body>
</html>
<%
return;
}
//有效
int studentIden = Integer.parseInt (studentId);
UniversityT.NotRegistered[] notRegistered = null;
boolean status = false;
int[] selectedCourses = new int[1];
selectedCourses[0] = Integer.parseInt(courseNum);
try {
//开始
TransCur.begin();
// 调用这测对象注册课程
notRegistered = univHelper.gRegistrarObjRef.register_for_courses(
studentIden,
selectedCourses);
boolean preventCommit = false;
if (notRegistered != null)
{
if (notRegistered.length > 0 )
{
for (int i = 0 ; i < notRegistered.length; i++)
{
%>
<html>
<head><title>Register For Course - Application Error</title></head>
<body bgcolor=#FFFFFF>
<p><img src=images/BEA_Button_Final_web.gif align=right>
<font face="Helvetica">
<center>
<h4>
<font color='#FF0000'>
Application Error: Either you are already registered for the course or an invalid course # was entered. This transaction will be rolled back
</font>
</h4>
<form>
<input type='button' value='Back' OnClick='history.go(-1)'>
</form>
<p>
Copyright (c) 1999-2000 by BEA Systems, Inc. All Rights Reserved.
</center>
</font>
</body>
</html>
<%
}
preventCommit = true;
}
}
if (!preventCommit)
{
boolean reportHeuristics = true;
TransCur.commit(reportHeuristics);
status = true;
%>
<html><head><title>Register For Course </title></head>
<body bgcolor=#FFFFFF>
<p><img src=images/BEA_Button_Final_web.gif align=right>
<font face="Helvetica">
<center>
<h><b>Registration Successful </b></h>
<form>
<input type='button' value='Back' OnClick='history.go(-1)'>
</form>
<p>
Copyright (c) 1999-2000 by BEA Systems, Inc. All Rights Reserved.
</center>
</body></html>
<%
}
else
{
TransCur.rollback();
try { Thread.sleep(3 * 1000); } // 3 seconds
catch (InterruptedException e) {}
status = false;
}
return;
}
catch(UniversityT.TooManyCredits e)
{
%>
<html>
<head><title>Register For Course - Error</title></head>
<body bgcolor=#FFFFFF>
<p><img src=images/BEA_Button_Final_web.gif align=right>
<font face="Helvetica">
<center>
<h4> <font color='#FF0000'>
Application Error: Too Many credits: Cannot have more than <%=e.maximum_credits%>. This transaction will be rolled back
</font> </h4>
<%
try
{
TransCur.rollback();
}
catch(org.omg.CosTransactions.NoTransaction nte)
{
%>
<html>
<head><title>Register For Course - Error</title></head>
<body bgcolor=#FFFFFF>
<p><img src=images/BEA_Button_Final_web.gif align=right>
<font face="Helvetica">
<center>
<h3> <font color='#FF0000'>
System Error: No Transaction: <%=nte.toString()%>
</font> </h3>
<%
}
}
catch(org.omg.CosTransactions.NoTransaction nte)
{
%>
<html>
<head><title>Register For Course - Error</title></head>
<body bgcolor=#FFFFFF>
<p><img src=images/BEA_Button_Final_web.gif align=right>
<font face="Helvetica">
<center>
<h3> <font color='#FF0000'>
System Error: No Transaction: <%=nte.toString()%>
</font> </h3>
<%
}
catch(org.omg.CosTransactions.SubtransactionsUnavailable e)
{
%>
<html>
<head><title>Register For Course - Error</title></head>
<body bgcolor=#FFFFFF>
<p><img src=images/BEA_Button_Final_web.gif align=right>
<font face="Helvetica">
<center>
<h3> <font color='#FF0000'>
System Error: Subtransactions Unavailable: <%=e.toString()%>
</font> </h3>
<%
}
catch(org.omg.CosTransactions.HeuristicHazard e)
{
%>
<html>
<head><title>Register For Course - Error</title></head>
<body bgcolor=#FFFFFF>
<p><img src=images/BEA_Button_Final_web.gif align=right>
<font face="Helvetica">
<center>
<h3> <font color='#FF0000'>
System Error: HeuristicHazard: <%=e.toString()%>
</font> </h3>
<%
}
catch(org.omg.CosTransactions.HeuristicMixed e)
{
%>
<html>
<head><title>Register For Course - Error</title></head>
<body bgcolor=#FFFFFF>
<p><img src=images/BEA_Button_Final_web.gif align=right>
<font face="Helvetica">
<center>
<h3> <font color='#FF0000'>
System Error: HeuristicMixed: <%=e.toString()%>
</font> </h3>
<%
}
%>
<form>
<input type='button' value='Back' OnClick='history.go(-1)'>
</form>
<p>
Copyright (c) 1999-2000 by BEA Systems, Inc. All Rights Reserved.
</center>
</font>
</body>
</html>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?