Results 1 to 4 of 4
  1. #1
    KKG
    KKG is offline Member
    Join Date
    Sep 2013
    Posts
    11
    Rep Power
    0

    Default display servlet response on the same page of jsp

    I have a servlet and a jsp page which shows the result of a .txt file (which is on my local machine)on the jsp page. My problem is when I click the VIEWLOG button on the jsp page it should show me the result on the same page. For example my VIEWLOG button is on a page called view.jsp, I should see the log on http://localhost:8080/Project/view.jsp But it is displaying the result in the following url
    http://localhost:8080/project/status?showstatus=Status. Any idea how can I get the result on the same page where VIEWLOG button is. Below is the code snippet.

    Servlet:

    public class Status extends HttpServlet {
    protected void doGet(HttpServletRequest req, HttpServletResponse res) throws
    IOException {


    try{
    PrintWriter out = res.getWriter();
    File file = new File("C:\\Debug\\logfile.txt");
    if (file.exists()) {
    BufferedReader input = new BufferedReader(new FileReader(file));
    String line = "";
    while ((line = input.readLine()) != null) {
    out.println(line);
    }
    }
    }
    catch (Throwable t)
    {
    t.printStackTrace();
    }


    finally {

    } }

    }

    JSP:

    <div id= "log" style="display:none;">
    <FORM action="logfile" METHOD="GET">
    <input type=submit name=showLog id=txtSubmit
    value=ViewLOG />
    </FORM>
    </div>

    WEB.XML:

    <servlet>
    <servlet-name>LogFile</servlet-name>
    <servlet-class>com.san.plc.LogFile</servlet-class>
    </servlet>
    <servlet-mapping>
    <servlet-name>LogFile</servlet-name>
    <url-pattern>/logfile</url-pattern>
    </servlet-mapping>

  2. #2
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,686
    Rep Power
    5

    Default Re: display servlet response on the same page of jsp

    Quickest solution would be to put the servlet in an IFrame that is part of your JSP.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  3. #3
    KKG
    KKG is offline Member
    Join Date
    Sep 2013
    Posts
    11
    Rep Power
    0

    Default Re: display servlet response on the same page of jsp

    Thanks for the response, but i have no idea what IFrame is and how it works

  4. #4
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,686
    Rep Power
    5

    Default Re: display servlet response on the same page of jsp

    So? Learn.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

Similar Threads

  1. servlet reques and response
    By BALUBALU in forum Java Servlet
    Replies: 1
    Last Post: 08-06-2012, 10:30 AM
  2. Replies: 0
    Last Post: 03-16-2012, 10:37 PM
  3. Servlet request and Response Size
    By giladma in forum Java Servlet
    Replies: 0
    Last Post: 09-23-2011, 03:27 PM
  4. InputStream/Response from Servlet fails: why?
    By gretty in forum Java Applets
    Replies: 0
    Last Post: 02-20-2011, 01:31 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •