4. JSP pages - code - in jsps folder

Mirjana's picture

  • index.html
<html>
<script language="javascript">
      location.href='jsps/login.jsp';
</script>
<body/>
</html>
 
  • login.jsp
 
<html>
 
<%
      String _logoutusr = (String)session.getAttribute("username");
      if (_logoutusr != null) session.invalidate();
%>
<%
      String message = request.getParameter("message");
      if (message == null) message = "Please log in";
      String title = request.getParameter("title");
      if (title == null) title= "Please log in";
 
%>
<head>
<title>Login</title>
</head>
<body bgcolor="#EFEFEF" onLoad="document.frm.username.focus()">
<div align="center">
<img src="/SOMU_webApp/images/mickey-mouse.gif">
 
<form action='checkautho.jsp' method='post' name='frm'>
   <table>
            <tr>
                  <td align="center" colspan="2"><%=title%></td>
            </tr>
      <tr>
        <td align='right'>Username</td>
        <td><input type='text' name='username'></td>
      </tr>
      <tr>
        <td align='right'>Password</td>
        <td><input type='password' name='password'></td>
      </tr>
      <tr>
        <td align='center' colspan=2><input type='submit' value=Login></td>
      </tr>
      <tr>
        <td align='center' colspan=2><%=message%></td>
      </tr>
   </table>
</form>
<br><b></b>
</html>
 
 
  • checkautho.jsp
 
<%@page contentType="text/html"%>
 
<%@ page import="java.util.*"%>
<%@ page import="com.sterlingcommerce.woodstock.security.*" %>
 
<%@ taglib uri='http://www.stercomm.com/uix/security' prefix='sec' %>
<%
String strUser = request.getParameter("username");
String strPass = request.getParameter("password");
%>
<sec:authenticate user="<%=strUser%>" pass="<%=strPass%>" login="login.jsp?title=USERNAME/PASSWORD INCORRECT!!!" />
<%
User u = (User) session.getAttribute("user");
int intTimeOut = u.getTimeout();
session.setAttribute("timeout", String.valueOf(intTimeOut));
session.setMaxInactiveInterval(intTimeOut);
session.setAttribute("username", strUser);
session.setAttribute("fullName", u.getFullName());
session.setAttribute("token", u.getUserToken());
%>
<jsp:forward page='jsp1.jsp'/>
 
<html>
<body>
 
</body>
</html>
 
  • jsp1.jsp

 

<%@page contentType="text/html; charset=UTF-8" pageEncoding="ISO-8859-1"%>
<%@page import="java.util.*,java.text.*"%>
<%@page import="org.w3c.dom.Document"%>
<%@page import="com.sterlingcommerce.woodstock.util.xml.XMLUtil"%>
<%@page import="com.sterlingcommerce.woodstock.security.*"%>
<%@page import="com.sterlingcommerce.woodstock.security.util.*"%>
<%@taglib uri="http://www.stercomm.com/uix/security" prefix="sec"%>
<%@taglib uri="http://jakarta.apache.org/taglibs/xtags-1.0" prefix="xtags"%>
 
<sec:validSession login="login.jsp?message=Session expired. Please log in again"/>
 
<%
                 
      SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
      String currentDate = formatter.format(new Date());   
 
%>         
           
<html>
<head>
      <title>JSP1</title>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>   
</head>
<body bgcolor="#EFEFEF">
<form id="testForm" name="testForm" method="post">
 
<br/>
<br/>
<table>
      <tr>
            <td>Enter the first parameter:</td>
            <td><input type='text' name='firstParam'></td>
      </tr>
      <tr>
            <td>Enter the second parameter:</td>
            <td><input type='text' name='secondParam'></td>
      </tr>
      <tr>
            <td colspan="2"><input type="submit" name="submit" value="Submit" onClick="document.testForm.action='jsp2.jsp'; document.testForm.submit();"/></td>
      </tr>
</table>
</form>
</body>
</html>
 
  • jsp2.jsp

 

<%@page contentType="text/html; charset=UTF-8" pageEncoding="ISO-8859-1"%>
<%@page import="java.util.*,java.text.*"%>
<%@page import="org.w3c.dom.Document"%>
<%@ page import="org.dom4j.*" %>
 
<%@page import="com.sterlingcommerce.woodstock.util.xml.XMLUtil"%>
<%@page import="com.sterlingcommerce.woodstock.security.*"%>
<%@page import="com.sterlingcommerce.woodstock.security.util.*"%>
<%@taglib uri="http://www.stercomm.com/uix/security" prefix="sec"%>
<%@taglib uri="http://jakarta.apache.org/taglibs/xtags-1.0" prefix="xtags"%>
 
<sec:validSession login="login.jsp?message=Session expired. Please log in again"/>
 
<%
 
      // taking username from the session
 
      String strUser = (String)session.getAttribute("username");
 
      // taking request params from jsp1.jsp
     
      String firstParam = request.getParameter("firstParam");
      String secondParam = request.getParameter("secondParam");
     
      // creating name value pair for sending params in Process Data
     
      StringBuffer stringBufferForPD = new StringBuffer();
     
      stringBufferForPD.append("firstParam=");
      stringBufferForPD.append(firstParam);
      stringBufferForPD.append("&");
      stringBufferForPD.append("secondParam=");
      stringBufferForPD.append(secondParam);
   
      String strNvp = stringBufferForPD.toString();
     
      // creating XML for Primary Document
     
      StringBuffer stringBufferForPrimaryDocument = new StringBuffer();
     
      stringBufferForPrimaryDocument.append("<inputDocument>\n");
     
      stringBufferForPrimaryDocument.append("<firstParam>");
      stringBufferForPrimaryDocument.append(firstParam);
      stringBufferForPrimaryDocument.append("</firstParam>\n");
 
      stringBufferForPrimaryDocument.append("<secondParam>");
      stringBufferForPrimaryDocument.append(request.getParameter("secondParam"));
      stringBufferForPrimaryDocument.append("</secondParam>\n");
           
      stringBufferForPrimaryDocument.append("</inputDocument>\n");
           
      String inputDocumentString = stringBufferForPrimaryDocument.toString();
     
      // define BP that will be run in SI system, when submitting this form
     
      String strBP = "SOMU_webapp_selectUsers";            
     
 
%>         
      <sec:autho permission="<%=strBP%>" checkExistence="true">        
            <sec:runBP user="<%=strUser%>" nvp="<%=strNvp%>" pridoc="<%=inputDocumentString%>" bpname="<%=strBP%>">                 
                  <%
                  String strBPResults = XMLUtil.documentToString(bpResults, false);
                  org.dom4j.Document d = new org.dom4j.io.DOMReader().read(bpResults);
                  pageContext.setAttribute("org.apache.taglibs.xtags.taglib.Context", d);
                  %>               
            </sec:runBP>                       
      </sec:autho>           
 
<html>
<head>
      <title>JSP2</title>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>   
</head>
<body bgcolor="#EFEFEF">
<form id="testForm" name="testForm" method="post">
<hr/>
List of users from Sterling Integrator:
<hr/>
<br/>
<br/>
<table border="1">
      <tr>
            <th>User ID</th>
            <th>First name</th>
            <th>Last name</th>
            <th>Email</th>
            <th>Session timeout</th>
            <th>Person info key</th>
      </tr>
      <xtags:forEach select="//RESULT/ROW">
            <tr>
                  <td><a href="jsp3.jsp?userParam=<xtags:valueOf select="USERNAME/text()"/>"><xtags:valueOf select="USERNAME/text()"/></a></td>
                  <td><xtags:valueOf select="FIRST_NAME/text()"/></td>
                  <td><xtags:valueOf select="LAST_NAME/text()"/></td>
                  <td><xtags:valueOf select="EMAILID/text()"/></td>
                  <td><xtags:valueOf select="SESSION_TIMEOUT/text()"/></td>
                  <td><xtags:valueOf select="PERSON_INFO_KEY/text()"/></td>
            </tr>
      </xtags:forEach>
</table>
 
<br/>
 
</body>
</html>
 
  • jsp3.jsp
 
<%@page contentType="text/html; charset=UTF-8" pageEncoding="ISO-8859-1"%>
<%@page import="java.util.*,java.text.*"%>
<%@page import="org.w3c.dom.Document"%>
<%@ page import="org.dom4j.*" %>
<%@page import="com.sterlingcommerce.woodstock.util.xml.XMLUtil"%>
<%@page import="com.sterlingcommerce.woodstock.security.*"%>
<%@page import="com.sterlingcommerce.woodstock.security.util.*"%>
<%@taglib uri="http://www.stercomm.com/uix/security" prefix="sec"%>
<%@taglib uri="http://jakarta.apache.org/taglibs/xtags-1.0" prefix="xtags"%>
 
<sec:validSession login="login.jsp?message=Session expired. Please log in again"/>
 
<%
      //taking username from the session
     
      String strUser = (String) session.getAttribute("username");
 
      //BP name that will be run
 
      String strBP = "SOMU_webapp_selectUserAuditDetails";             
     
      //taking userParam from request
     
      String userParam = request.getParameter("userParam");
     
      //defining userParam for nvp, will be set in the Process Data
     
      String nvp = "userParam=" + userParam;
     
%>         
      <sec:autho permission="<%=strBP%>" checkExistence="true">        
            <sec:runBP user="<%=strUser%>" nvp="<%=nvp%>" pridoc="" bpname="<%=strBP%>">             
                  <%
                  String strBPResults = XMLUtil.documentToString(bpResults, false);
                  org.dom4j.Document d = new org.dom4j.io.DOMReader().read(bpResults);
                  pageContext.setAttribute("org.apache.taglibs.xtags.taglib.Context", d);
                  %>               
            </sec:runBP>                       
      </sec:autho>           
 
<html>
<head>
      <title>JSP3</title>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>   
</head>
<body bgcolor="#EFEFEF">
<form id="testForm" name="testForm" method="post">
<hr/>
<table>
      <tr>
            <td>Audit details for the user <i style="color:red;"><%=userParam%></i></td>
            <td><input type="submit" name="submit" value="Back - list of users" onClick="document.testForm.action='jsp2.jsp'; document.testForm.submit();"/>
            <td><input type="submit" name="submit" value="First page" onClick="document.testForm.action='jsp1.jsp'; document.testForm.submit();"/></td>
      </tr>
</table>
<hr/>
<br/>
<br/>
 
<table>
      <tr>
            <th align="left">Object type</th>
            <th align="left">Object name</th>
            <th align="left">Action type</th>
            <th align="left">Action value</th>
            <th align="left">Time of changes</th>
      </tr>
      <xtags:forEach select="//RESULT/ROW">
      <tr>
            <td><b><xtags:valueOf select="OBJECT_TYPE/text()"/></b></td>
            <td><input type="text" name="firstName" size="32" readonly="readonly" value=<xtags:valueOf select="OBJECT_NAME/text()"/>></td>
            <td><input type="text" name="lastName" size="32" readonly="readonly" value=<xtags:valueOf select="ACTION_TYPE/text()"/>></td>
            <td><input type="text" name="email" size="32" readonly="readonly" value=<xtags:valueOf select="ACTION_VALUE/text()"/>></td>
            <td><input type="text" name="address" size="32" readonly="readonly" value=<xtags:valueOf select="TIME/text()"/>></td>
      </tr>
      </xtags:forEach>
           
</table>
 
 
</form>
</body>
</html>