Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 8 of 8

Thread: reg how to use log in jsp page

  1. #1
    Junior Member
    Join Date
    Apr 2010
    Posts
    18
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default reg how to use log in jsp page

    hi,
    i m wrkng on web-application...in it i m wrkng with jsp,servlets,html pages....i was assigned to create logs...
    with servlet i tried logs...its wrkng fine....the problem is how to write logs in jsp page...bcoz the proj. includes more of jsp pages....any one help me out...

    thnxs,
    Madhuri.


  2. #2
    Senile Half-Wit Freaky Chris's Avatar
    Join Date
    Mar 2009
    Posts
    834
    My Mood
    Cynical
    Thanks
    7
    Thanked 105 Times in 90 Posts

    Default Re: reg how to use log in jsp page

    JSP page gets compiled down to a serverlet anyway so in princile its exactly the same.

    Just remeber that to declare 'session' data you must use <?! ?>

    Regards,
    Chris

  3. #3
    Super Moderator Json's Avatar
    Join Date
    Jul 2009
    Location
    Warrington, United Kingdom
    Posts
    1,274
    My Mood
    Happy
    Thanks
    70
    Thanked 156 Times in 152 Posts

    Default Re: reg how to use log in jsp page

    It will be really hard for you to log stuff in an html file but in your jsp file you can do something like this.

    <%
        final Logger myLogger = new LoggerOrWhatever();
        myLogger.info("This is an INFO log message generated from the JSP");
    %>

    If you want to be slick you could however create your own little tag that would do the logging for you and then you could put something like this in your jsp file.

    <mytaglib:logger>This is my log message which accepts el, just look at ${myvariable}</mytaglib:logger>

    Oh and on another note, jsp's are not compiled into servlets, jsp are compiled into byte code by the application container and in tomcats case this is usally done by Jasper which is a JSP compiler.

    In the standard setup of Tomcat there is a default web.xml for the server which has a servlet defined to handle jsp files so whenever you use a request dispatcher to forward a user to a jsp file it will be handled by the JSP servlet.

        <servlet>
            <servlet-name>jsp</servlet-name>
            <servlet-class>org.apache.jasper.servlet.JspServlet</servlet-class>
            <init-param>
                <param-name>fork</param-name>
                <param-value>false</param-value>
            </init-param>
            <init-param>
                <param-name>xpoweredBy</param-name>
                <param-value>false</param-value>
            </init-param>
            <load-on-startup>3</load-on-startup>
        </servlet>
     
        <servlet-mapping>
            <servlet-name>jsp</servlet-name>
            <url-pattern>*.jsp</url-pattern>
        </servlet-mapping>
     
        <servlet-mapping>
            <servlet-name>jsp</servlet-name>
            <url-pattern>*.jspx</url-pattern>
        </servlet-mapping>

    // Json

  4. The Following User Says Thank You to Json For This Useful Post:

    javaking (April 9th, 2010)

  5. #4
    Senile Half-Wit Freaky Chris's Avatar
    Join Date
    Mar 2009
    Posts
    834
    My Mood
    Cynical
    Thanks
    7
    Thanked 105 Times in 90 Posts

    Default Re: reg how to use log in jsp page

    From the reading I've recently done on JSP it was suggesting that depening on what server you are running it will with be compiled straight to byte code, or take an intermediate for of a servelet and then is compiled down from there.

    But thanks for sharing your info Json

    Chris

  6. #5
    Junior Member
    Join Date
    Apr 2010
    Posts
    18
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: reg how to use log in jsp page

    hi,
    thanx for ur information....i tried it but im unable to wrk the program.....
    can u provide me any example....
    bye.

  7. #6
    Super Moderator Json's Avatar
    Join Date
    Jul 2009
    Location
    Warrington, United Kingdom
    Posts
    1,274
    My Mood
    Happy
    Thanks
    70
    Thanked 156 Times in 152 Posts

    Default Re: reg how to use log in jsp page

    I just did provide you with two examples in the above post, what does your code look like?

    What are you reading about JSP's atm Chris?

    // Json

  8. #7
    Senile Half-Wit Freaky Chris's Avatar
    Join Date
    Mar 2009
    Posts
    834
    My Mood
    Cynical
    Thanks
    7
    Thanked 105 Times in 90 Posts

    Default Re: reg how to use log in jsp page

    Just random stuff, i was just having a quikc look over them so I have a basic knowledge of what they do and how.

  9. #8
    Junior Member
    Join Date
    Apr 2010
    Posts
    18
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: reg how to use log in jsp page

    hi Json,
    Gud mrng....thanx a lot....i tried wht u snd me the code.....its wrkng fine...once again thanx a lot.
    Bye.

Similar Threads

  1. Need help in login page in struts
    By vinothkumarrvk in forum Web Frameworks
    Replies: 4
    Last Post: October 4th, 2011, 02:10 PM
  2. Need help in JSP Page
    By vinothkumarrvk in forum Web Frameworks
    Replies: 1
    Last Post: March 12th, 2010, 07:43 AM
  3. Problem in JSP Page Designing
    By vinothkumarrvk in forum JavaServer Pages: JSP & JSTL
    Replies: 0
    Last Post: March 10th, 2010, 01:09 AM
  4. Need help in JSP Page
    By vinothkumarrvk in forum JavaServer Pages: JSP & JSTL
    Replies: 0
    Last Post: March 9th, 2010, 05:20 AM
  5. Page Replacement Algorithms
    By smokeyjoey in forum Algorithms & Recursion
    Replies: 2
    Last Post: December 7th, 2009, 10:38 PM