Solved

how to add a function to a jsp file

Posted on 2009-07-07
4
933 Views
Last Modified: 2012-05-07
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
0
Comment
Question by:dbnoob
  • 2
4 Comments
 
LVL 92

Expert Comment

by:objects
ID: 24801068
put it in a java class, you can then call it from either jsp
0
 

Author Comment

by:dbnoob
ID: 24801183
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">&nbsp;</td>

								<td class="LoginError" nowrap="nowrap" colspan="2" id="LoginMsg-id">&nbsp;</td>

							</tr>

							<tr>

								<td class="login" nowrap="nowrap" width="20">&nbsp;</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" >&nbsp;</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">&nbsp;</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">&nbsp;</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">&nbsp;</td>

								<td class="loginfield" nowrap="nowrap">&nbsp;</td>

								<td>

									<input type="button" name="login" value="<%=MessageTranslation.getLocalizedText(locale, "Log In")%>" onClick="doLogin();"><!--;-->&nbsp;

									<input type="button" name="clear" value="<%=MessageTranslation.getLocalizedText(locale, "Clear")%>" onClick="clearLogin();"><!--;-->

								</td>

							</tr>

							<tr>

								<td class="Login" nowrap="nowrap">&nbsp;</td>

								<td class="Login" nowrap="nowrap">&nbsp;</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>&nbsp;</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">&nbsp;</td>

						<td>

						<p class="caption"><%=MessageTranslation.getLocalizedText(locale,"&#xa9; 2006 BMC Software, Inc. All rights reserved.")%></p>

						</td>

					</tr>

				</tbody></table>

				</td>

			</tr>

		</tbody></table>

		</td>

	</tr>

</tbody></table>
 
 

</body>

</html>

Open in new window

0
 
LVL 6

Accepted Solution

by:
jwenting earned 500 total points
ID: 24801521
Don't put Java code in a JSP.
Rather put it in a servlet and use the JSP only to display the result using JSTL or JSF EL.
0
 

Author Closing Comment

by:dbnoob
ID: 31600974
abandoned.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

With more and more people tethered to the internet, advertisers can reach you in new and creative ways. Push notifications on your smartphone, customized advertisements based on your previous searches, and email inboxes filled with promotional pitch…
Note: This is the third blog post in a series on email clearinghouses (https://www.xmatters.com/alert-management/blog-email-has-failed-us?utm_campaign=70138000000ydLoAAI&utm_source=exex&utm_medium=article&utm_content=blog-post).   We’ve been talki…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

947 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now