dbnoob
asked on
how to add a function to a jsp file
This is my first attempt at javascript-
I have 2 files (attached):
login.jsp (login page for web app).
info.jsp (contains functions)
Both files work fine by themselves for separate purposes, but i'm trying to figure out how to
incorporate the function env_RemoteUser_Login() from info.jsp to populate the User Name field in login.jsp
I have 2 files (attached):
login.jsp (login page for web app).
info.jsp (contains functions)
Both files work fine by themselves for separate purposes, but i'm trying to figure out how to
incorporate the function env_RemoteUser_Login() from info.jsp to populate the User Name field in login.jsp
put it in a java class, you can then call it from either jsp
ASKER
I'm including the code from both files now, since it doesn't look like the attachments took in the original post.
info.jsp
// JavaScript Document
function env_RemoteAddr() {
return ("<%=request.getRemoteAddr()%>"); }
function env_RemoteHost() {
return ("<%=request.getRemoteHost()%>"); }
function env_RemoteUser() {
return ("<%=request.getRemoteUser().replace('\\', ' ')%>"); }
function env_RemoteUser_Domain() {
var return_value = "<%=request.getRemoteUser().replace('\\', ' ')%>";
var pos = return_value.indexOf(' ');
if (pos < 0) return ('');
return (return_value.substring(0, pos)); }
function env_RemoteUser_Login() {
var return_value = "<%=request.getRemoteUser().replace('\\', ' ')%>";
var pos = return_value.indexOf(' ');
return_value = return_value.toLowerCase();
if (pos > 0) return (return_value.substring(pos+1, 99)); return (return_value); }
***********************************************
login.jsp
<%@page pageEncoding="UTF-8"%>
<%@page contentType="text/html; charset=UTF-8"%>
<!--
Title: login.jsp
Copyright (c) 2001-2006 BMC Software, Inc.
All rights reserved.
This software is the confidential and proprietary information of
BMC Software, Inc ("Confidential Information"). You shall not
disclose such Confidential Information and shall use it only in
accordance with the terms of the license agreement between
you and BMC Software, Inc.
This is a generic ARSystem login page. This page is accessed/displayed when:
1. User accesses AR form and have not logged in or is not a valid user on server where form resides.
2. User invokes login page directly with request parameters.
These parameters allow user to specify the next page (html/jsp)
to goto and which server to login to. Syntax requires both parameters to be specified.
<Usage>
http://host/arsys/shared/login.jsp?goto=uri&server=name
uri = absolute or relative from application context
name = server name
3. User is redirected back to login page after initial login fails.
This page can be customized for your specific site with the following exceptions:
Form action must invoke the LoginServlet and method must be post.
ACTION="<%=request.getContextPath()%>/servlet/LoginServlet"
METHOD="post"
REQUIRED PARAMETERS:
username = Request parameter specifying user name.
pwd = Request parameter specifying user password.
OPTIONAL PARAMETERS - Although optional it is advised that these parameters not be removed.
timezone = Request parameter containing time zone information detected from the browser environment.
auth = Request parameter containing authentication string (ie: NT domain).
arsys_login_name = Session parameter returned with the user's name if an error occured during login.
arsys_login_msg = Session parameter returned containing a message if an error occurred during login.
arsys_login_user_error = Session parameter indicating an incorrect username.
arsys_login_password_error = Session parameter indicating an incorrect password
-->
<%
response.addHeader("Cache-Control", "no-cache");
%>
<%@ page import="com.remedy.arsys.share.MessageTranslation" %>
<%@ page import="com.remedy.arsys.config.Configuration" %>
<%@ page import="com.remedy.arsys.session.Params" %>
<html>
<head>
<script src="<%=request.getContextPath()%>/shared/TimezoneFinder.js" defer=1></script>
<!-- common to all localized login pages -->
<%@ include file="login_common.jsp" %>
<title><%=titleStr%> - <%=MessageTranslation.getLocalizedText(locale, "Login")%></title><!--;-->
</head>
<body onLoad="initLogin();" topmargin="0" leftmargin="0" rightmargin="0" bottommargin="0" >
<table border="0" cellpadding="0" cellspacing="0" height="100%" width="100%">
<!-- main table (wraps around sub-tables) -->
<tbody><tr>
<td valign="top">
<table border="0" cellpadding="20" cellspacing="0" width="100%">
<!-- header table -->
<tbody><tr>
<td bgcolor="#ffffff" width="100%">
<table border="0" cellpadding="20" cellspacing="0" width="100%">
<tbody><tr>
<td valign="bottom">
<p class="product">BMC Remedy Action Request System</p>
</td>
<td align="right" valign="bottom">
<img src="<%=logo_img%>" width="136" height="31" alt="BMC logo" border="0">
</td>
</tr>
</tbody></table>
</td>
</tr>
</tbody></table>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<!-- login area -->
<tbody><tr>
<td width="483">
<img src="<%=login_img%>" border="0" height="190" width="484"></td>
<td bgcolor="#0069a5">
<table cellpadding="2" cellspacing="0" width="340">
<form name="loginForm" METHOD="post"
ACTION="<%=request.getContextPath()%>/servlet/LoginServlet"
enctype="x-www-form-encoded">
<tbody>
<tr>
<td class="login" nowrap="nowrap" width="20"> </td>
<td class="LoginError" nowrap="nowrap" colspan="2" id="LoginMsg-id"> </td>
</tr>
<tr>
<td class="login" nowrap="nowrap" width="20"> </td>
<td class="login" colspan="2" nowrap="nowrap">
<p class="subhead"><%=MessageTranslation.getLocalizedText(locale,"Please log in.")%></p>
</td>
</tr>
<tr>
<td class="login" nowrap="nowrap" width="20" > </td>
<td class="login" nowrap="nowrap" id="LoginLabel-id">
<b><label for="username-id"><%=MessageTranslation.getLocalizedText(locale,"User Name")%></label></b>
</td>
<td>
<input name="<%=Params.USERNAME%>" maxlength="30" id="username-id" value="<%=com.remedy.arsys.share.HTMLWriter.escape(name)%>" class="loginfield" size="30" type="text">
</td>
</tr>
<tr>
<td class="login" nowrap="nowrap" width="20"> </td>
<td class="login" id="PasswordLabel-id" nowrap="nowrap">
<label for="pwd-id"><%=MessageTranslation.getLocalizedText(locale,"Password")%></label>
</td>
<td>
<input name="<%=Params.PASSWORD%>" id="pwd-id" class="loginfield" size="30" type="password">
</td>
</tr>
<tr>
<td class="Login" nowrap="nowrap" width="20"> </td>
<td class="Login" name="auth_label" nowrap="nowrap">
<label for="auth-id"><%=MessageTranslation.getLocalizedText(locale,"Authentication")%></label>
</td>
<td><input type="text" NAME="<%=Params.AUTHENTICATION_STRING%>" id="auth-id" maxlength="30" class="loginfield" size="30"></td>
</tr>
<tr>
<td class="Login" nowrap="nowrap" width="20"> </td>
<td class="loginfield" nowrap="nowrap"> </td>
<td>
<input type="button" name="login" value="<%=MessageTranslation.getLocalizedText(locale, "Log In")%>" onClick="doLogin();"><!--;-->
<input type="button" name="clear" value="<%=MessageTranslation.getLocalizedText(locale, "Clear")%>" onClick="clearLogin();"><!--;-->
</td>
</tr>
<tr>
<td class="Login" nowrap="nowrap"> </td>
<td class="Login" nowrap="nowrap"> </td>
<td>
<input type="hidden" name="<%=Params.TIMEZONE%>" value="">
<input type="hidden" name="<%=Params.PASSWORD_ENCRYPTED%>" value="1">
<input type="hidden" name="<%=Params.GOTO_URL%>" value="<%=com.remedy.arsys.share.HTMLWriter.escape(nextPage)%>" >
<input type="hidden" name="<%=Params.SERVER%>" value="<%=com.remedy.arsys.share.HTMLWriter.escape(server)%>" >
<input type="hidden" name="<%=Params.IP_OVERRIDE%>" value="0">
<input type="hidden" name="initialState" value="-1">
</td>
</tr>
</tbody>
</form>
</table>
</td>
</tr>
</tbody></table>
<!-- customizable text area -->
<div align="center">
<table border="0" cellpadding="20" cellspacing="0" width="100%" id="table1">
<tr>
<td width="100%"><% if(iframeurl != null) {%>
<iframe src="<%=iframeurl%>"></iframe>
<%}%>
</td>
</tr>
</table>
</div>
<!-- END customizable text area -->
<p> </p>
</td>
</tr>
<tr>
<td valign="bottom">
<table border="0" cellpadding="10" cellspacing="0" width="100%">
<!-- footer table -->
<tbody><tr>
<td bgcolor="#e8e8e1">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody><tr>
<td width="30"> </td>
<td>
<p class="caption"><%=MessageTranslation.getLocalizedText(locale,"© 2006 BMC Software, Inc. All rights reserved.")%></p>
</td>
</tr>
</tbody></table>
</td>
</tr>
</tbody></table>
</td>
</tr>
</tbody></table>
</body>
</html>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
abandoned.