Relative Address in a JSP page

How I will define relative address of a file inside jsp page
I have the following jsp page under ../web directory
<html>
<head>
</head>
<body>
<%
FileReader f_reader;
StringTokenizer stoken;
BufferedReader input = new BufferedReader(new FileReader("file.txt"));
%>
</html>
Here, the file.txt is also in ../web directory
When I execute the jsp page. I got the error --- file.txt is not found
I need ur help to short out the problem.
Thanks in advance
Ranjan Yengkhom

I answered similar question yesterday: [http://forums.sun.com/thread.jspa?threadID=5335480].

Similar Messages

  • How do you display images relative to a Portlet JSP page?

    For Welblogic Portal 7.0, I want to display a simple image (.gif) on a JSP page.
    The problem is that I need to use a 'hard coded' url to the image such as the following:
    <img src="portlets/test/images/test.gif" border="0" alt="Test 1">
    - OR -
    <img src="<webflow:createResourceURL resource="/portlets/test/images/test.gif" />"
    border="0" alt="Test 2">
    This makes the portlet less portable.
    My goal is to display an image relative to the current JSP Portlet page (in the test
    directory).
    Does anyone know how to accomplish this?
    In WL Portal 4.0 I used:
    <img src="<%=fixupRelativeURL(pathFromRequest(request) + "images/test.gif", request)%>"
    width=24 height=22 border=0 alt="test">
    This does not work anymore as fixupRelativeURL does not seem to exist in the 7.0
    API.
    Your help would be greatly appreciated!
    Thanks,
    Matt

    Exactly what I was looking for!
    Thank you Subbu.
    Subbu Allamaraju <subbuATBeaDOTCom> wrote:
    Matt,
    There is an indirect way to achieve this.
    (a) In your portlet JSP, get the PortletState. There is an example in
    /framework/portlet.jsp.
    (b) Get the content URL for this portlet by calling
    portletState.getUrl(Portlet.URL_CONTENT).
    Depending on where your image is (with respect to the content URL), you
    can construct a new URL to the image. For example if your content is at
    at /portlets/myportlet/foo.jsp and your image is in at
    /portlets/myportlet/images/myimage.gif, you can reconctruct the latter
    from the first one.
    Once you do this, prepend the constructed URL with the web app context
    root (request.getContextPath()).
    Hope this helps.
    Subbu
    matt wrote:
    For Welblogic Portal 7.0, I want to display a simple image (.gif) on aJSP page.
    The problem is that I need to use a 'hard coded' url to the image suchas the following:
    <img src="portlets/test/images/test.gif" border="0" alt="Test 1">
    - OR -
    <img src="<webflow:createResourceURL resource="/portlets/test/images/test.gif"/>"
    border="0" alt="Test 2">
    This makes the portlet less portable.
    My goal is to display an image relative to the current JSP Portlet page(in the test
    directory).
    Does anyone know how to accomplish this?
    In WL Portal 4.0 I used:
    <img src="<%=fixupRelativeURL(pathFromRequest(request) + "images/test.gif",request)%>"
    width=24 height=22 border=0 alt="test">
    This does not work anymore as fixupRelativeURL does not seem to existin the 7.0
    API.
    Your help would be greatly appreciated!
    Thanks,
    Matt

  • Creating a File object in a JSP page

    Hi,
    I am trying to create a File object in my JSP page by passing it a relative path. The jsp page is in 'website/testfolder/index.jsp' and the File is in 'website/photos/1.jpg'. In my jsp page i do the following:
    <% File f = new File("../photos/1.jpg");
    boolean test = f.isFile(); %>
    The value returned is false. I am trying to figure out why it can't locate the file.
    Thanks

    You have to use absolute paths. You can get the absolute path for the given relative path by ServletContext#getRealPath().

  • Can't use relative paths in jsp pages or javabeans

    Hi everyone,
    Can someone please help me with this little problem.
    When I want to use in a JSP page the object 'FileReadInput' to read in a file, it can't find when I only give the filename. The target file and source file are in the same directory so I would expect if I only give the filename, it will automatically search in the current directory. But when I give the complete absolute path, everything works fine. Is it possible to use relative paths in a jsp or javabean file?
    By the way, I am working with JDeveloper from Oracle. (maybe that has something to do with my problem)
    Can someone help me???
    Thx

    My dear friend,
    It will not work at all. coz, for any jsp file, ur application server will create a .java file and then .class file in a directory other than the directory where ur .jsp file present. that's why, ur file to be read can't be found. that's why use the following.
    String path=getServletConfig().getServletContext().getRealPath("/")+File.seperator+"yourfilename";

  • Absolute and relative addressing for stylesheets: issue with IE6 and pages not in the root

    The following conditional comment gives me a problem when I arrange my site into folders (instead of all pages in one directory, or all in the root). The directories are built according to the site hierarchy.
    <!--[if lte IE6]>
    <link rel="stylesheet" media="all" type="text/css" href="../styles/dropdown_ie.css />
    <![endif]-->
    <!--[if IE]>
    My homepage is in the rootfolder, the dropdown_ie.css is in the folder "styles".
    I use the dropdown menu from Stu Nichols http://www.cssplay.co.uk/menus/dd_valid.html and this works as long as all pages are in the same folder (or, in my case, as long as they all are together with the homepage in the rootfolder). But when pages are in different folders, the dropdown_ie.css is not read anymore when using IE6. Other browsers are ok; for those I use:
    <style type="text/css">
    <!--
    @import url("../styles/flyout.css");
    @import url("../styles/dropdown.css");
    -->
    </style>
    What do you suggest I do to get the pages not in the root to read the dropdown_ie.css file when using IE6?
    And I have a feeling that the way I import the styles may not be right, but I am not sure.
    Any help will be greatly appreciated.
    Erik

    I solved this one by changing the relative addressing of my stylesheet location in absolute addressing. And I had to do this not only for the stylesheet, but for all addressing in the html related to this drop down menu:
    href="http://mysafety.be/styles/dropdown_ie.css"
    Changing the location of my files into subdirectories (and removing the spaces in the file names) also means that all my google indexing got screwed up; I submitted to google the whole list of addresses for removal from their cache. It will be another 4 weeks before everything is indexed correctly again, but I guess I better do this now before the site becomes fully operational.

  • How to address form controls in jsp page

    Hello,
    I have a very stupid question. How do i empty the textfield value in my jsp page. I know that i can make a function that does that. but i dont know how to adress the control. Its got to be something like txtfield.setValue("myvalue") but i just dont know
    i cant find anything either on the internet. can somebody help me plz?
    thx very much,
    Kim

    Hi Kim,
    You can use the following JavaScript command:
    document.nameField.value = theValue;
    You can use this on submit of the form or in a click event at the field.
    I hope it be useful

  • Launching a Discoverer report from jsp page

    Hi
    I have a discoverer workbook created using BI Discoverer (for relational). I want to accept some parameters for this workbook from a jsp page, which will also have a "View report" button. This button when pressed should open up the Discoverer workbook and all the parameters from the jsp should be passed to the workbook.
    Is it possible? If yes, any details on it?
    We do the same thing successfully to launch Oracle Reports from jsps, we simply build the url in the jsp, and from jsp we submit it to a new window, and it opens up the report. Similar functionality we are looking to launch Discoverer reports.
    Any help will be appreciated.
    Thanks
    Shalu

    You can open the workbook with URL parameters with Discoverer Viewer much like you would Oracle Reports. Setting anything form the username, password, workbook name, worksheet, and parameters. All the information can be found in the following document:
    http://download-east.oracle.com/docs/cd/B14099_11/bi.1012/b13918/urlstart.htm
    The specific question your asking is addressed under 13.5.2 Example 2. Let me know if you have any issues
    Matt Topper
    Technical Management Consultant
    TUSC, The Oracle Experts
    [email protected]

  • How to include a .class file in a jsp page

    hi everyone,
    i know the syntax as:
    <%@ include file = "filename.class" %>
    then at run time the server could not find the class file
    if i use,
    <%@ page import = "FileName.class" %>
    then also the same problem persists
    & if i use
    <jsp:include page = "Relative address"/>
    the problem still remains as it is...
    please help me out...i am working on developing an EJB application in which client interacts with server's Stateful session bean through a jsp page...it is necessary for me to include the home interface class file in my jsp page.
    P.S. do not suggest me to include the class file in a package & then use
    <%@ page import = "packageName.ClassFileName" %>
    i
    Edited by: Ankit_JIITU on 6 Jul, 2008 1:55 AM

    Ankit_JIITU wrote:
    i have already included the remote interface class file by <%@ page import = "University.RemoteInterfaceName" %>in my jsp page ...
    if i try to make a new package called test & then include my home interface in that package...i need to import University.*to generate the class file of my home interface ; but the class file generation is not taking place as i am getting the error..
    "package University does not exist".How can i overcome this problem. The package University, which you are trying to import, must be in the classpath. If you removed it then you will have to add it back.
    i have tried my best..but tell me if there's any possible way of including a class file in the jsp page without involving a package.No, there isn't.
    If not,then pls help me to generate the class file of my home interface within a package called test.Read the New To Java Tutorial and understand how packages work.
    >
    i am assuming that u have a deep knowledge of developing EJB applications.

  • Single signon between JSP page and Net.Data page

    I am trying to setup a single signon between a JSP page hosted on a tomcat server, and a Net.Data page hosted on an IBM HTTP server. Both of these servers are running on an AS400. The JSP page (www.jsppage.com/menu) contains a link to the Net.Data page (www.netData.com/page2). In order to access www.jsppage.com/menu the user needs to login. Once this happens I want them to be able to go back and forth between the two pages without having to log in when they switch servers. Page navigation is handled through myServlet.java so that when a user clicks on a link the request is forwarded on to myServlet.java where the servlet determines where to redirect the user to. The servlet uses
    RequestDispatcher requestDispatcher = getServletContex().getRequestDispatcher(url);
    requestDispatcher.forward(request, response);
    to forward the user to the correct page. This works fine for the JSP pages but when I forward to www.netData.com/page2 I get an error telling me the address doesn't start with a /. I also need to send the user name and password for the net.data pages to avoid the second login window to popup.
    I understand that the requestDsipatcher.forward() method directs the browser to a page that is relative to the current root directory. If I try to use response.sendRedirect(url) I get sent to the right page but the signon window pops up. I would appreciate any help.

    I am trying to setup a single signon between a JSP
    page hosted on a tomcat server, and a Net.Data page
    hosted on an IBM HTTP server. Both of these servers
    are running on an AS400. The JSP page
    (www.jsppage.com/menu) contains a link to the Net.Data
    page (www.netData.com/page2). In order to access
    www.jsppage.com/menu the user needs to login. Once
    this happens I want them to be able to go back and
    forth between the two pages without having to log in
    when they switch servers. Page navigation is handled
    through myServlet.java so that when a user clicks on a
    link the request is forwarded on to myServlet.java
    where the servlet determines where to redirect the
    user to. The servlet uses
    RequestDispatcher requestDispatcher =
    getServletContex().getRequestDispatcher(url);
    requestDispatcher.forward(request, response);
    to forward the user to the correct page. This works
    fine for the JSP pages but when I forward to
    www.netData.com/page2 I get an error telling me the
    address doesn't start with a /. I also need to send
    the user name and password for the net.data pages to
    avoid the second login window to popup.
    I understand that the requestDsipatcher.forward()
    method directs the browser to a page that is relative
    to the current root directory. If I try to use
    response.sendRedirect(url) I get sent to the right
    page but the signon window pops up. I would
    appreciate any help.You can't do that without passing username and password.
    The servers keep track of the user by storing a cookie on the clients computer. The cookie is only valid for the domain that created it.
    So, to make this work you need to send the username and password as part of the sendRedirect. the forward() method won't work.
    What you could do is create some code on the .net machine that accepts username, password and target URL as input. Once it receives those parameters it should perform the .net login procedure and redirect to the correct page.
    In your servlet you should pass those parameters on to the .net machine and the user should get the correct page without ever seeing any login windows.
    Make sure to use https if you decide to follow this scheme since http will transmit the username/password in cleartext.
    /Christopher

  • How to use single JSP page for multiple users.

    Hi ,
    I am doing messenger kind of program using JSP and tomcat server.
    When i type message it is showing in the some div. If some other person request for the same page by giving my IP address and jsp page, he should able to see what i have typed on page so far.
    how can i do that one . can any one guide me .
    Thanks in advance.

    SuneelGoodatJava wrote:
    Hi ,
    I am doing messenger kind of program using JSP and tomcat server.
    When i type message it is showing in the some div. If some other person request for the same page by giving my IP address and jsp page, he should able to see what i have typed on page so far.
    how can i do that one . can any one guide me .
    Thanks in advance.HTTP is a request/response protocol. You can't do what you're suggesting without "pushing" what you type to all the other users. That's not the way HTTP works. Maybe an applet and servlet.
    %

  • Issue in applying SSL selectively to Login JSP Page--Session getting lost.

    Hi,
    I am facing some issues with SSL configuration on my web site running on tomcat 5.5. I am using jdk 1.5 and form based authentication with JAAS framework.
    The SSL configuration is working perfectly when applied to complete web site, but starts giving problem when applied selectively to some JSP pages. At present I am trying to apply SSL just on the login page.
    When the login screen loads up, the URL in the browser has a protocol "*https*", as expected, but it doesn't gets changed to "*http*" once the user has successfully logged in. Why is the automatic change from https to http not ocurring?
    Also I want to know which is the default page, tomcat will direct the logged in user to, once successfully authenticated using form based login; Is there any way to change this default page to some other page. It looks like that tomcat automatically directs to index.html , once the user has been successfully authenticated, but I am not so sure. My index.html page is having 4 frames; the source of these frames are different JSP pages, which are not under SSL.
    My aim is to apply SSL just on login.jsp so that password doesn't travel in clear text. Once the user is authenticated he should see index.html and the address bar's URL should change it's protocol from https to http.
    Please, find below the code in my web.xml
    <security-constraint>
    <web-resource-collection>
    <web-resource-name>CWA Application</web-resource-name>
    <url-pattern>/about.jsp</url-pattern>
    <url-pattern>/admin_listds.jsp</url-pattern>
    <http-method>DELETE</http-method>
    <http-method>GET</http-method>
    <http-method>POST</http-method>
    <http-method>PUT</http-method>
    </web-resource-collection>
    <auth-constraint>
    <role-name>*</role-name>
    </auth-constraint>
    <user-data-constraint>
    <transport-guarantee>NONE</transport-guarantee>
    </user-data-constraint>
    </security-constraint>
    <security-constraint>
    <web-resource-collection>
    <url-pattern>/*login.jsp*</url-pattern>
    <http-method>GET</http-method>
    <http-method>POST</http-method>
    </web-resource-collection>
    <auth-constraint>
    <role-name>*</role-name>
    </auth-constraint>
    <user-data-constraint>
    <transport-guarantee>CONFIDENTIAL</transport-guarantee>
    </user-data-constraint>
    </security-constraint>
    <login-config>
    <auth-method>FORM</auth-method>
    <realm-name>CWA Application</realm-name>
    <form-login-config>
    <form-login-page>/login.jsp</form-login-page>
    <form-error-page>/login.jsp?error=true</form-error-page>
    </form-login-config>
    </login-config>
    <welcome-file-list>
    <welcome-file>login.jsp</welcome-file>
    </welcome-file-list>
    My login. jsp has below code:
    <form name="login" method="POST" action='<%= response.encodeURL(*"j_security_check*") %>' >
    <tr>
    <td width="100%">
    <table width="260" border="0" cellspacing="0" cellpadding="1">
    <tr>
    <td align="left" valign="top" rowspan="4"><img src="images/space.gif" width="15" height="5"></td>
    <td align="right" class="login-user" nowrap ><p>User name: </p></td>
    <td align="left" valign="top"><input maxLength="64" name="j_username" size="20"></td>
    </tr>
    <tr>
    <td align="right" nowrap class="login-user"><p>Password: </p>
    </td>
    <td align="left" valign="top">
    <input maxLength=\"64\" tabindex="2" type="password" name="j_password" size="20">
    </td>
    </tr>
    </form>
    The entries in my server.xml are following:
    <Connector port="8080" maxHttpHeaderSize="8192"
    maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
    enableLookups="false" redirectPort="8443" acceptCount="100"
    connectionTimeout="20000" disableUploadTimeout="true" />
    <Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
    maxThreads="150" scheme="https" secure="true"
    keystoreFile="${java.home}\lib\security\cacerts" keystorePass="changeit"
    clientAuth="false" sslProtocol="TLS" />
    I have gone through the http://forums.sun.com/thread.jspa?threadID=197150 and tried implementing it; The filter as explained in the thread does gets called but the session values are still lost.
    Please note I am using javascript to go from secure "https" to "http" once the user has successfully logged in The javascript code is as below:
    top.location.href="http://localhost:8080/qtv/index.html." ;
    If I use response.sendRedirect("http://localhost:8080/qtv/index.html") for going to non-secure mode, the index.html page does not gets loaded properly. (Please note that my index.html is made of *4 frames*, as explained earlier. This is a legacy code and frames can't be removed).
    The reason for index.html not getting loaded properly is that the Address bar URL does NOT change its URL and protocol from https (https://localhost:8443/qtv/index.html ) to "*http*" (http://localhost:8080/qtv/index.html) when esponse.sendRedirect() is used ;this is the default behaviour of response.sendRedirect(). And because the protocol in address bar is https, index.html is not able to load the other JSP's in it's frames because of cross-frame-scripting security issues (The other JSP's to be loaded in frames are are NOT secure as discussed earlier).
    Please let know if any way out.
    Thanks,
    Masaai

    Hi
    try to set the maximum interval between requests
    eg:
    session.setMaxInactiveInterval(6000);
    vis

  • Pls help me writing logic:iterate tag in jsp page

    Hey guys , I am struck in retriving string p1,p2,p3 in the jsp page
    Pls have a look ata the code
    In DAO class:-
    StdprdDAO.java
    Public arrayList getPFP()
    ArrayList a = new ArrayList();
    While(rs.next())
         columnsVO colVO = new columnsVO;
         colVO.setProduct(rset.getString(1));//will store in String colProduct
         colVO.setFamily(rset.getString(2));//will store in String colFamily
    colVO.setPrice(rset.getString(3));//will store in String colPrice
    a.add(colVO);
    return a;
    In Action Class:-
    ArrayList final = null;
    StdprdDAO DAO = new stdprdDAO();
    final = DAO.getPFP();
    For(int i = 0; final !=null && i<final.size() ; i++)
         columnsVO VO = null;
         VO = (columnsVO)final.get(i);
         String p1 = (String) VO.getProduct();
         String p2 = (String) VO.getFamily();
         String p3 = (String) VO.getPrice();
         Request.setAttribute(“p1”,p1);
         Request.setAttribute(“p2”,p2);
         Request.setAttribute(“p3”,p3);
    In JSP PAGE:-
    id = “columnsVO”>
    <bean:write name = “columnsVO” property=”final” id=”p1”>
    but still I am doubting my above sentences in jsp page ,so pls correct them if possible.
    Instead of l;ogic:iterate can I use directly getattribute(“p1”)? <logic:iterate
    Still I m doubting I can not utilize columnsVO file in logic:iterate, I can utilize only formbean file.
    So pls help me with this.

    May I ask why have you done it?
    If it is related to printing of the list then it is of no use.But it IS of use. The objects compEmployees is in scope.
    It has the list we want to print out.
    With logic:iterate:
    <table>
         <tr>
           <th>Number</th>
           <th>Employee</th>
         </tr>
         <logic:iterate name="compEmployees" property="totalEmps" id="emp">
              <tr>
                <td>
                  <bean:write name="emp" property="empNo"/>
                </td>
                <td>
                  <bean:write name="emp" property="empName"/>
                </td>
              </tr>
         </logic:iterate>
    </table>or alternatively with JSTL and c:forEach
    <table>
         <tr>
           <th>Number</th>
           <th>Employee</th>
         </tr>
         <c:forEach items="${compEmployees.totalEmps}" var="emp">
              <tr>
                <td>
                  <c:out value="${emp.empNo}"/>
                </td>
                <td>
                  <c:out value="${emp.empName}"/>
                </td>
              </tr>
         </c:forEach>
    </table>Cheers,
    evnafets

  • Post and Get value in jsp page

    I have two pages
    1. Occasion.jsp
    2. Occasionsdetail.jsp
    i select values from database in occasion for example
    a
    b
    c
    they become links when i click on one of these links it call Occasiondetail form. Where i want to display details of that particular record
    On occasion page i am passing value which is displaying in last of address bar of occasionsdetail page
    How can i use that value in occasiondetail form
    both files code is pasted
    Occasions.jsp
    <head>
    <title>
    Riphah International University
    </title>
    </head>
    <body bgcolor="#ffffff">
    <form method="POST" action="occasionDetails.jsp">
    <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
    <tr>
    <td align="center" bgcolor="#6633FF"> <strong><font color="#000000">Occasions</font></strong> </td>
    </tr>
    <% org.riu.db.utility.DBHandler dbHandler = new org.riu.db.utility.DBHandler();
    if ( dbHandler.getConnection() ) {
    org.riu.db.datastructureaccess.OccasionAccess occasionAccess = new org.riu.db.datastructureaccess.OccasionAccess(dbHandler);
    java.util.ArrayList occasions = occasionAccess.getOccasions();
    if ( occasions == null || occasions.isEmpty() ) { %>
    <tr>
    <td align="center">
    </td>
    </tr>
    <% } else {
    for ( int i = 0; i < occasions.size(); i++ ) {
    org.riu.db.datastructure.Occasion occasion = (org.riu.db.datastructure.Occasion) occasions.get(i); %>
    <tr>
    <td align="center">
    <a href="occasionDetails.jsp?OccasionID <%=occasion.getOccasionID() %> "><%= occasion.getName() %></a> <%= " on " + occasion.getDate() %><%= + occasion.getSemesterID()%>
    </td>
    </tr>
    <tr>
    <td align="center">
    <hr />
    </td>
    </tr>
    <% }
    } %>
    </table>
    <p align="center">Back</p>
    </form>
    </body>
    </html>
    OccasionDetail.jsp
    <head>
    <title>
    Riphah International University
    </title>
    </head>
    <body bgcolor="#ffffff">
    <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
    <tr>
    <td align="center" bgcolor="#6633FF"> <strong><font color="#000000">Occasion Details</font></strong> </td>
    </tr>
    <% org.riu.db.utility.DBHandler dbHandler = new org.riu.db.utility.DBHandler();
    if ( dbHandler.getConnection() ) {
    org.riu.db.datastructureaccess.OccasionAccess occasionAccess = new org.riu.db.datastructureaccess.OccasionAccess(dbHandler);
    java.util.ArrayList occasions = occasionAccess.getOccasionswhere(I want to use that value here);
    // new Integer(request.getParameter("OccasionID")).intValue();
    if ( occasions == null || occasions.isEmpty() ) { %>
    <tr>
    <td align="center">
    </td>
    </tr>
    <% } else {
    for ( int i = 0; i < occasions.size(); i++ ) {
    org.riu.db.datastructure.Occasion occasion = (org.riu.db.datastructure.Occasion) occasions.get(i);%>
    <tr>
    <td align="center">
    Venue: <%= occasion.getVenue()%>
    </td>
    </tr>
    <tr>
    <td align="center">
    Time: <%= occasion.getTime() %>
    </td>
    </tr>
    <tr>
    <td align="center">
    <hr />
    </td>
    </tr>
    <% }
    } %>
    </table>
    <p align="center">Back</p>
    </body>
    </html>

    Are your records javascript variables? If so, you can use a json formatter to serialize the records to a string and send it from PageA to PageB using mechanism that supports strings (i.e. query parameter, cookie, etc).
    You can learn more about json at http://www.json.org/ and about a json serializer/parser at http://www.json.org/js.html .

  • JSP page is coming back with old data even when DB updated

    Hello,
    I am updating an existing record on a database using an HTML form and the changes update the ACCESS database immediately, but the .jsp page is picking up
    old data.
    But but when i do a manual REFRESH, the correct data comes back fine!
    Thanks very much for any insights!
    Summary of the code:
    1. InputEmployeeInfo.html - enter change data, call update....jsp
    <HEAD> <meta content="no-cache" http-equiv="Cache-Control"/>
    <meta content="no-cache" http-equiv="Pragma"/> </HEAD>
    <FORM NAME="updateInfo"
    ACTION="./UpdateEmployeeInfo.jsp" >>>>>2.
    METHOD="POST">
    2. UpdateEmployeeInfo.jsp: - call bean, update database, forward to present..jsp
    <HEAD> <meta content="no-cache" http-equiv="Cache-Control"/>
    <meta content="no-cache" http-equiv="Pragma"/>
    </HEAD>
    <% response.setHeader("Cache-Control","no-cache");
    response.setHeader("Pragma","no-cache");
    response.setDateHeader ("Expires", 0); %>
    <jsp:useBean id="empInfo"
    class="com.ora.jsp.beans.employee23.EmployeeInfoBean" >>>>>3.
    scope="request"/>
    <jsp:setProperty name="empInfo" property="*" />
    <% empInfo.updateDatabase(); %> >>>>>3b.
    <jsp:forward page="PresentChangeOfEmployeeData.jsp" /> >>>>>4.
    </BODY>
    </HTML>
    3. com.ora.jsp.beans.employee23.EmployeeInfoBean - Bean-update DB with change data
    public class EmployeeInfoBean {
    public void updateDatabase(){                                            <----3b.
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
    Connection conn =
    DriverManager.getConnection("jdbc:odbc:example");
    String sql = "UPDATE EMPLOYEEINFO SET " +
    "NAME=?, ADDRESS=?, PHONE=? WHERE ID=?";
    PreparedStatement statement = conn.prepareStatement(sql);
    statement.setString(1, name);
    statement.setString(2, address);
    statement.setString(3, phone);
    statement.setInt(4, id);
    statement.executeQuery();
    statement.close();
    conn.close();
    4. PresentChangeOfEmployeeData.jsp - read database and display changes <----4.
    <HEAD> <meta content="no-cache" http-equiv="Cache-Control"/>
    <meta content="no-cache" http-equiv="Pragma"/>
    </HEAD>
    <% response.setHeader("Cache-Control","no-cache");
    response.setHeader("Pragma","no-cache");
    response.setDateHeader ("Expires", 0); %>
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
    Connection conn =
    DriverManager.getConnection("jdbc:odbc:example");
    Statement statement = conn.createStatement();
    String sql = "SELECT * FROM EMPLOYEEINFO WHERE ID = " + employeeID;
    ResultSet rs = statement.executeQuery(sql);
    while(rs.next()){
    %>
    <TR><TD ALIGN="right" WIDTH="50%">Name:</TD>
    <TD WIDTH="50%"><%= rs.getString("NAME") %></TD>
    ================================================================================
    Complete code listing:
    1, InputEmployeeInfo.html
    <HTML>
    <HEAD>
    <meta content="no-cache" http-equiv="Cache-Control"/>
    <meta content="no-cache" http-equiv="Pragma"/>
    <TITLE>Change of Information</TITLE>
    </HEAD>
    <BODY>
    <TABLE WIDTH="100%" BORDER="0" BGCOLOR="navy">
    <TR ALIGN="center">
    <TD><FONT SIZE="7" COLOR="yellow">Employee Information</FONT></TD>
    </TR>
    </TABLE>
    <CENTER>
    <FONT SIZE="5" COLOR="navy">
    Please Enter Your Information<BR>
    Fill in all fields
    </FONT>
    </CENTER>
    <TABLE WIDTH="100%">
    <FORM NAME="updateInfo"
    ACTION="./UpdateEmployeeInfo.jsp" >>>>>>>>>2.
    METHOD="POST">
    <TR><TD WIDTH="40%" ALIGN="right">Current ID: </TD>
    <TD WIDTH="60%"><INPUT TYPE="text" NAME="id"></TD>
    </TR>
    <TR><TD WIDTH="40%" ALIGN="right">New Name: </TD>
    <TD WIDTH="60%"><INPUT TYPE="text" NAME="name" VALUE="Mickey"></TD>
    </TR>
    <TR><TD WIDTH="40%" ALIGN="right">New Address: </TD>
    <TD WIDTH="60%">
    <INPUT TYPE="text" NAME="address" VALUE="St. Louis, MO">
    </TD>
    </TR>
    <TR><TD WIDTH="40%" ALIGN="right">New Phone: </TD>
    <TD WIDTH="60%">
    <INPUT TYPE="text" NAME="phone" VALUE="555-555-1234">
    </TD>
    </TR>
    <TR><TD COLSPAN="2" ALIGN="center">
    <INPUT TYPE="submit" NAME="btnSubmit" VALUE="Update Profile"></TD>
    </TR>
    </TABLE>
    </FORM>
    </BODY>
    </HTML
    2. UpdateEmployeeInfo.jsp:
    <HTML>
    <HEAD>
    <meta content="no-cache" http-equiv="Cache-Control"/>
    <meta content="no-cache" http-equiv="Pragma"/>
    <TITLE>Updating Employee Information</TITLE>
    </HEAD>
    <BODY>
    <% response.setHeader("Cache-Control","no-cache");
    response.setHeader("Pragma","no-cache");
    response.setDateHeader ("Expires", 0);
    %>
    <jsp:useBean id="empInfo"
    class="com.ora.jsp.beans.employee23.EmployeeInfoBean" >>>>>>>>>>>>>3.
    scope="request"/>
    <jsp:setProperty name="empInfo" property="*" />
    <% empInfo.updateDatabase(); %> >>>>>>>>>>>>>3b.
    <jsp:forward page="PresentChangeOfEmployeeData.jsp" /> >>>>>>>>>>>>>4.
    </BODY>
    </HTML>
    3. com.ora.jsp.beans.employee23.EmployeeInfoBean <-------------3.
    package com.ora.jsp.beans.employee23;
    import java.sql.*;
    public class EmployeeInfoBean {
    private String name, address, phone;
    private int id;
    public void setName(String input){
    name = input;
    public String getName(){
    return name;
    public void setAddress(String input){
    address = input;
    public String getAddress(){
    return address;
    public void setPhone(String input){
    phone = input;
    public String getPhone(){
    return phone;
    public void setId(int input){
    id = input;
    public int getId(){
    return id;
    public void updateDatabase(){                                       <-------3b.
    try{
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
    Connection conn =
    DriverManager.getConnection("jdbc:odbc:example");
    String sql = "UPDATE EMPLOYEEINFO SET " +
    "NAME=?, ADDRESS=?, PHONE=? WHERE ID=?";
    PreparedStatement statement = conn.prepareStatement(sql);
    statement.setString(1, name);
    statement.setString(2, address);
    statement.setString(3, phone);
    statement.setInt(4, id);
    statement.executeQuery();
    statement.close();
    conn.close();
    catch (Exception e) {}
    4. PresentChangeOfEmployeeData.jsp <---------4.
    <HTML>
    <HEAD>
    <meta content="no-cache" http-equiv="Cache-Control"/>
    <meta content="no-cache" http-equiv="Pragma"/>
    <TITLE></TITLE>
    </HEAD>
    <BODY>
    <% response.setHeader("Cache-Control","no-cache");
    response.setHeader("Pragma","no-cache");
    response.setDateHeader ("Expires", 0);
    %>
    <%@ include file="CompanyBanner.html"%>
    <%@ page import="java.sql.*" %>
    <jsp:useBean id="empInfo"
    class="com.ora.jsp.beans.employee23.EmployeeInfoBean"
    scope="request"/>
    <CENTER>
    <FONT SIZE="5" COLOR="navy">
    Your New Information
    </FONT>
    </CENTER>
    <TABLE WIDTH="100%" BORDER="1">
    <%
    int employeeID = empInfo.getId();
    try {
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance(); <--------4b,
    Connection conn =
    DriverManager.getConnection("jdbc:odbc:example");
    Statement statement = conn.createStatement();
    String sql = "SELECT * FROM EMPLOYEEINFO WHERE ID = " + employeeID;
    ResultSet rs = statement.executeQuery(sql);
    while(rs.next()){
    %>
    <TR><TD ALIGN="right" WIDTH="50%">Name:</TD>
    <TD WIDTH="50%"><%= rs.getString("NAME") %></TD>
    </TR>
    <TR><TD ALIGN="right" WIDTH="50%">Address:</TD>
    <TD WIDTH="50%"><%= rs.getString("ADDRESS") %></TD>
    </TR>
    <TR><TD ALIGN="right" WIDTH="50%">Phone Number:</TD>
    <TD WIDTH="50%"><%= rs.getString("PHONE") %></TD>
    </TR>
    <TR><TD ALIGN="right" WIDTH="50%">Work Status:</TD>
    <TD WIDTH="50%"><%= rs.getString("WORKSTATUS") %></TD>
    </TR>
    <TR><TD ALIGN="right" WIDTH="50%">Total Sick Days:</TD>
    <TD> <%= rs.getString("TOTALSICKDAYS") %></TD>
    </TR>
    <TR><TD ALIGN="right" WIDTH="50%">Taken Sick Days: </TD>
    <TD><%= rs.getString("TAKENSICKDAYS") %></TD>
    </TR>
    <TR><TD ALIGN="right" WIDTH="50%">Total Personal Time(in hours): </TD>
    <TD><%= rs.getString("TOTALPERSONALTIME") %></TD>
    </TR>
    <TR><TD ALIGN="right" WIDTH="50%">Taken Personal Time(in hours): </TD>
    <TD><%= rs.getString("TAKENPERSONALTIME") %></TD>
    </TR>
    <TR><TD ALIGN="right" WIDTH="50%">Health Care Plan:</TD>
    <TD WIDTH="50%"><%= rs.getString("HEALTHCAREPLAN") %></TD>
    </TR>
    <TR><TD ALIGN="right" WIDTH="50%">Dental Plan:</TD>
    <TD WIDTH="50%"><%= rs.getString("DENTALPLAN") %></TD>
    </TR>
    <TR><TD ALIGN="right" WIDTH="50%">Vision Plan:</TD>
    <TD WIDTH="50%"><%= rs.getString("VISIONPLAN") %></TD>
    </TR>
    <% }//end while loop
    } // end try block
    catch (Exception e) {};
    %>
    </TABLE>
    <%@ include file="ch24_SiteNavigator.html" %>
    </BODY>
    </HTML>

    <%
    String dept_name=request.getParameter("D1");
    String itmp,itmcd,sn;
    %>
    <%
    Connection con;
    PreparedStatement ps;
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    con=DriverManager.getConnection("jdbc:odbc:acc");
    Statement stmt=con.createStatement();
    ResultSet rs=stmt.executeQuery("select * from item_details where Item_Name='"+dept_name+"'
    %>
    <td> Product name</td>
    <td>Product description</td>
    <td><Product code</td>
    <td>Product price</td></tr>
    <form method=post action="mycreate.jsp">
    <%
    while(rs.next())
    %><tr>
    <%=rs.getString(1)%></td>
    <%=rs.getString(4)%></td>
    <td><font color="#ffffff" size="3" face="arial unicode
    ms">    <%=rs.getString(3)%></td>
    <% String temp=rs.getString(3);%>
    <%=temp%>
    <td>
    <%=rs.getString(5)%></td>
    <td><input type=submit value="Add to cart"></td></tr>
    <form method=post action="mycreate.jsp">
    <%
    con.close();
    %>
    </tr>
    </table></tr></table></tr></table>
    </form>
    </form>
    I want the value of rs.getString(3) in a variable

  • How to get the value from a database without submitting a jsp page

    I have a jsp which has a text box depending on the value entered I want to get the value from a database for other two fields with out submitting jsp page. I am using struts.
    Thanks For any assistance provided.

    Alright,here is an example for you for the first case.
    Present.jsp:
    ============
    <html:html>
    <head>
    <title><html:message key="page.title"/></title>
    </head>
    <body>
    <html:form action="ChangeEvent.do">
    <html:hidden property="method"/>
    <!-- Submitting the Form onKeyUp of EmpId field and trying to save the
         state of the Form in the scope of session -->
    Emp Id:<html:text property="empId" size="5"  onkeyup="if(true){this.form.elements[0].value='populateDetails';this.form.submit();}"/>
    Emp Name:<html:text property="empName" size="10" />
    Email Address:<html:text property="email" size="10" />
    <html:submit>Submit</html:submit>
    </html:form>
    </body>
    </html:html>struts-config.xml:
    ==================
    <?xml version="1.0" encoding="ISO-8859-1" ?>
    <!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">
    <struts-config>
    <!-- Form bean which stores the properties of all the Form elements -->
    <form-beans>
    <form-bean name="employeeFormBean" type="org.apache.struts.action.DynaActionForm">
       <form-property name="empId" type="java.lang.String"/>
       <form-property name="empName" type="java.lang.String"/>
       <form-property name="email" type="java.lang.String" />   
    </form-bean>
    </form-bean>
    <action-mappings>
    <action path="/ChangeEvent" type="Test.GetChangeAction" name="employeeFormBean" scope="request" parameter="method"> 
    <!-- On successful call of DB the Page has to be forwarded to the same page again by
          uploading updated form bean values. -->
    <forward name="success" path="/Present.jsp"></forward>
    <forward name="failed" path="/error.jsp"></forward>
    </action>
    </action-mappings>
    </struts-config>GetChangeAction.java:
    =====================
    public class GetChangeAction extends DispatchAction{
      public ActionForward populateDetails(ActionMapping mapping,ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
            DynaActionForm dForm = (DynaActionForm)form;
            String empId = dForm.get("empId");     
            // calling Model / Db and then getting back Employee Details
            EmployeeBean eb = ModelUtils.getDetails(empId);
            // Updating form bean by updating values from the Model 
            dForm.set("empName".eb.getEmpName()); 
            dForm.set("email".eb.getEmail());
            return mapping.findForward("success");
    }well to me this should work regardless to any browser but we need to make sure we put in our logic properly.

Maybe you are looking for