Writing a JSP introduction/tutorial

Greetings everyone,
I'm a college student finishing up a Co-op term and have been asked to write a document that introduces a group of programmers to JSP.
The big idea he wants to me to touch upon is the advantages of using beans in JSP pages. Does anyone have any points that I should definately write about?
Think back to when you were learning JSP and ask yourself if there was something that you know now that would have really helped back then. It is things like those that I wish to include.
Any other suggestions for such an article would be handy as well.
If I get enough interest I might try to convince my supervisor to let me publish it on the web.
Thanks!
Kefka

using javabeans in jsp pages will allow u to encapsulate all kind business logic in the form of bean and allow jsp page to include only presentation details thus releaving it from messy chunks of core logic code and presentation code together. javabeans are used as resusable components(pieces of code) in the jsp page ...thus u get a high degree of seperation between content presentation and content generation using javabeans in jsp pages.....

Similar Messages

  • File Writing with JSP

    Hi all,
    I'm creating a simple app that gets form data and populates it to a file. I want to make sure that each instance (thread?) is able to write to the file and not throw an exception since the file may be currently open by another instance of the jsp. Now I did basic thread programming in C++ a long time ago, so I'm aware of thread waiting conceptually, but I'm not familiar with the java implementation. Can someone show me some basic syntax on how I would go in essentially putting a lock on the file writing portion of the code.
    Thanx much

    I disagree that you should override anything in Threa, especiially the sleep method.
    What you should do is handle the file writing in a producer/consumer fashion. Have a single class that extends Runnable be the consumer. It handles all the file writing issues. You will run this in its own thread.
    Your JSPs (or other threads) fill in a collection, or some other holder, which informs the consumer to write to the file.
    As a brief example, this is a mini logger type of program. I use a class (LogCenter) to log data put in it from other sources (client1 and client2). For the sake of using newer API, I make use of the java.util.concurrent.BlockingQueue (and java.util.concurrent.LinkedBlockingQueue) to make a thread-safe collection and reporting system for text to come in and out of the logger.
    Note, this is far from production. Just something I whipped up when playing with blocking queues a while ago...
    package net.thelukes.steven.thread.test;
    import java.io.PrintWriter;
    import java.util.concurrent.BlockingQueue;
    import java.util.concurrent.LinkedBlockingQueue;
    public class LoggingCenter implements Runnable {
      private PrintWriter output;
      private BlockingQueue<String> toPrint;
      public LoggingCenter() {
        toPrint = new LinkedBlockingQueue<String>(10);
      public void setOutput(PrintWriter pw) {
        if (pw == null)  {
          if (output != null)
            return; //do not replace output with null
          else //pw is null and output is null
            throw new IllegalArgumentException("Ouput PrintWriter must not be NULL");
        else {
          if (output != null) closeOutput(); //if output exists already, close it.
          output = pw;
      public void log(String text) {
        boolean added = false;
        while (!added)
          try {
            toPrint.put(text);
            added=true;
          } catch (InterruptedException ie) {
            ie.printStackTrace();
            try { Thread.sleep(300L); }
            catch (InterruptedException ie2) { ie2.printStackTrace();}
      public void run() {
        try {
          while (true) {
            printLn(toPrint.take());
        } catch (InterruptedException ie) {ie.printStackTrace();}
      private void closeOutput() {
        output.flush();
        output.close();
      private void printLn(String text) {
        if (output == null)
          throw new IllegalStateException
            ("The Output PrintWriter must be set before any output can occur.");
        output.println(text);
        output.flush();
    package net.thelukes.steven.thread.test;
    import java.io.File;
    import java.io.FileWriter;
    import java.io.IOException;
    import java.io.PrintWriter;
    public class LoggingTest {
      public static void main(String[] args) throws IOException {
        PrintWriter output = new PrintWriter(
          new FileWriter(new File("log.txt")));
        //PrintWriter output = new PrintWriter(System.out, true);
        final LoggingCenter logger = new LoggingCenter();
        logger.setOutput(output);
        Thread t = new Thread(logger);
        t.start();
        Thread client1 = new Thread(
            new Runnable() {
              public void run() {
                while (true) {
                  logger.log("Client 1: "+System.currentTimeMillis());
                  try {
                    Thread.sleep(1250L);
                  } catch (InterruptedException e) {}
        Thread client2 = new Thread(
            new Runnable() {
              public void run() {
                while (true) {
                  logger.log("Client 2: "+System.currentTimeMillis());
                  try {
                    Thread.sleep(2500L);
                  } catch (InterruptedException e) {}
        client1.start();
        client2.start();
    }

  • JSP & Sevlet tutorial..

    Is there a site that provide Basic to Advance tutorial on Servlet and JSP? Please let me know....
    jun

    Try http://www.coreservlets.com.
    "Trying is the first step toward failure." - Homer J. Simpson

  • Need help in writing a .jsp page

    Hi Guys,
    I am new to JSP. My requirement is " I have a link on my webpage. When the user clicks that link, a HTML page is displayed which has parameters to be entered (for ex: from_date , to_date). When the user clicks the submit button, a jsp page should be displayed in which a query is run to display the output. For example, the user enters the from_date and to_date parameter values to know the employees employed within those dates in their company. The query is "select empname,empno,sal,dept,comm from emp where employed_date between from_date and to_date" . The following should run and display in the jsp page.
    How can i write a .jsp to extract the parameters that are entered in the HTML form in to a .jsp and run the query with those parameters to display the output. Help needed in making me write this .jsp for this query.
    Help Aprreciated.
    Thanks

    Hm, your requirements sound like homework assignment from classroom. If so, is itn't better that you find the answer youself? There are plenty of very relevant references for how to use jsp to handle html forms or talk to a rdbms through a jdbc connection. For example, for jsp and html forms, you can google "jsp html forms"; for jsp and sql query, search for "jsp jdbc".
    Tell me if this is not helpful.

  • Writing Login.jsp and authenticating a user who have stored in MySql DB

    Hi Friends,
    My project requirement is: Need to write a login page must send the request to servlet is the user and password avail in mysql db, if yes servlet should forward the home page else error message. Tools i need to use is IDE=eclipse, Server = tomcat, database = MySql
    Here is source:
    pls tell me where i m wrong.
    Login.jsp
    <%@ page language="java" %>
    <html>
    <head>
    <title>Login Page</title>
    <script language = "Javascript">
    function Validate(){
    var user=document.frm.user
    var pass=document.frm.pass
    if ((user.value==null)||(user.value=="")){
    alert("Please Enter user name")
    user.focus()
    return false
    if ((pass.value==null)||(pass.value=="")){
    alert("Please Enter password")
    pass.focus()
    return false
    return true
    </script>
    </head>
    <body>
    <h1>Login
    <br>
    </h1>
    <form name="frm" action="/LoginAuthentication" method="Post" onSubmit="return Validate()" >
    Name:
    <input type="text" name="user" value=""/><br>
    Password:<input type="password" name="pass" value=""/><br>
    <br>
    <input type="submit" value="Login" />
    <input type="reset" value="forgot Password" />
    </form>
    </body>
    </html>
    Servlet Code:
    LoginAuthentication.java
    import java.io.*;
    import java.util.*;
    import java.sql.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.io.IOException;
    import javax.servlet.ServletException;
    import javax.servlet.ServletContext;
    import javax.servlet.RequestDispatcher;
    import javax.servlet.http.HttpSession;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import java.util.List;
    import java.util.ArrayList;
    public class LoginAuthentication extends HttpServlet{
    private ServletConfig config;
    public void init(ServletConfig config)
    throws ServletException{
    this.config=config;
    //public void init() {
    // Normally you would load the prices from a database.
    //ServletContext ctx = getServletContext();
    // RequestDispatcher dispatcher = ctx.getRequestDispatcher("/HomePage.jsp");
    //dispatcher.forward(req, res);
    public void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException,IOException{
    PrintWriter out = response.getWriter();
    String connectionURL = "jdbc:mysql://127.0.0.1/SRAT";
    //String connectionURL = "jdbc:mysql://192.168.10.59/SRAT";
    //127.0.0.1
    //http://localhost:3306/mysql
    Connection connection=null;
    ResultSet rs;
    String userName=new String("");
    String passwrd=new String("");
    response.setContentType("text/html");
    try {
    // Load the database driver
    Class.forName("com.mysql.jdbc.Driver");
    // Get a Connection to the database
    connection = DriverManager.getConnection(connectionURL, "admin", "admin");
    //Add the data into the database
    String sql = "select user,password from login";
    Statement s = connection.createStatement();
    s.executeQuery (sql);
    rs = s.getResultSet();
    while (rs.next ()){
    userName=rs.getString("user");
    passwrd=rs.getString("password");
    rs.close ();
    s.close ();
    }catch(Exception e){
    System.out.println("Exception is ;"+e);
    if(userName.equals(request.getParameter("user"))
    && passwrd.equals(request.getParameter("pass"))){
    out.println("WELCOME "+userName);
    else{
    out.println("Please enter correct username and password");
    out.println("<a href='Login.jsp'><br>Login again</a>");
    Deployment Descriptor for TOMCAT
    web.xml
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
    <display-name>
    SRAT</display-name>
    <welcome-file-list>
    <welcome-file>login.jsp</welcome-file>
    </welcome-file-list>
    <servlet>
    <servlet-name>LoginAuthentication</servlet-name>
    <servlet-class>LoginAuthentication</servlet-class>
    </servlet>
    <servlet-mapping>
    <servlet-name>LoginAuthentication</servlet-name>
    <url-pattern>/LoginAuthentication</url-pattern>
    </servlet-mapping>
    </web-app>
    PLS HELP ME.
    S. Udaya Chandrika

    I too have used the same code but its giving the following error:
    HTTP Status 500 -
    type Exception report
    message
    description The server encountered an internal error () that prevented it from fulfilling this request.
    exception
    javax.servlet.ServletException: Wrapper cannot find servlet class Validation or a class it depends on
         org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
         org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
         org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
         org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
         org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
         java.lang.Thread.run(Unknown Source)
    root cause
    java.lang.ClassNotFoundException: Validation
         org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1387)
         org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1233)
         org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
         org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
         org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
         org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
         org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
         java.lang.Thread.run(Unknown Source)
    note The full stack trace of the root cause is available in the Apache Tomcat/6.0.18 logs.
    Apache Tomcat/6.0.18
    Please some one help??

  • Simple introduction/tutorial on how to make Cocoa-Applescript Applets?

    I'm looking for a simple tutorial on how to make Cocoa-Applescript Applets.  I'm pretty new to Applescript, but fairly good at it, and I was wondering how Cocoa-Applescript Applets worked.  I was curious as I've been wondering if it was possible to somehow display images in Applescript, and it apparently is the only/easiest way.  My problem is that I haven't been able to find any tutorials on using it, so I was wondering if you guys could point me in the right direction, that'd be great!
    thanks in advance

    The main difference is with how the Cocoa APIs are used - in addition to the AppleScript and AppleScriptObjC release notes, there are some examples and resources at Mac OS X Automation.  Note that in Yosemite, AppleScriptObjC is available to all scripts, not just applets and libraries.

  • Has anyone worked with IntelliJ IDEA for writing a JSP?

    Hi!
    I have just begun using IntelliJ IDEA4.5. I was previously using Weblogic7.0, now i have had to switch to ver.6.0.In IDEA'S Application Servers settings, whenever i try to select "C:\bea" as the bea home directory, it says that "C:\bea not a valid home directory".Is this 'coz i uninstalled 7.0 & then reinstalled 6.0 ?
    I tried looking up in all the help i could get about IDEA, but there's no help regarding this problem.If someone could atleast refer me to a link, discussion forum,etc. for the same, it would be of great help.I'm really a beginner in JSPs.
    Thanks in advance,
    Deepthy.

    I have used IntelliJ for quite a while now. I have a question. Is then when you are initially setting up IntelliJ right after install or is this a setting somewhere in IntelliJ?
    it sounds like the error you get when you are initially setting up IntelliJ, when it asks for importing previous settings.

  • Any body help me in writing a JSP page

    I want to write a JSP page through which i can store the downloaded file in to client machine please help me fast

    Hi,
    Thanks, My question i can't do that thing by using a JSP file, I am not getting that any body can give me the code for a JSP file. I am not getting by using this code-------
    s1=request.getParameter("text");
    URL url = new URL("s1");
    URLConnection connection = url.openConnection();
    InputStream stream = connection.getInputStream();
    BufferedInputStream in = new BufferedInputStream(stream);
    FileOutputStream file = new FileOutputStream("result.txt");
    BufferedOutputStream os = new BufferedOutputStream(file);
    int i;
    while ((i = in.read()) != -1) {
    os.write(i);
    Its giving some Internal error
    When I am specifying some url like "http://www.sun.com" in the place of s1 its not showing any error but its not opening that page.
    Pleaseeeeeeeee give me some solution for this
    Thanks In advance

  • Working with interdependent listboxes: A tutorial.

    Working with interdependent listboxes in Creator.
    I have an application with several listboxes that are interdepoendant of one another. That is to say, that when one entry gets selected, the value on one or more other listboxes gets updated.
    When I first coded up a solution for this, I was having trouble with some errors thrown internally to the components. After a lot of digging and with the help of Sun, I was able to cure this problem, so I am writing up this brief tutorial to help others do something similar.
    Let me tart of with what the application looks like:
    The GUI
    In this application we have three listboxes and some 2D and 3D images that get loaded based on the values selected in those listboxes.
    When the first listbox is changed, then the second and third listboxes automatically get changed based on the value selected in the first. In other words, the value selected in listbox1 will be retrieved and then that value will be used to retrieve data (in my case from a database) to be used in populating the second and third listboxes.
    Let�s also say that we want to automatically select the listbox entry if only one item exists.
    What Creator Does Today
    In Creator 1, when you drop a listbox on a page a defaultListboxItems list gets created for you in the backing page bean. This is what you would normally expect to add items to fill your listbox.
    Of course, this data gets reset for every refresh of that page. In our case, when we select an item on on of the listboxes the page will be refreshed (Submitted). Because of this, you might place a list in the session bean and retrieve it in the page bean�s constructor (which of course gets called for each page refresh) and use that list to rebuild your defaultListboxItems list.
    That however, as I found out, is probably not the best way to do it.
    The �Right� Way
    As mentioned above, we need a way to keep the values of the listboxes saved off in between page refreshes.
    The way to do this is to place that into the session bean and only there. In other words, you will not be using the defaultListboxItem list that Creator set up for you inside the page bean. Instead, you will create your own which will look something like this (again, this code will go inside of the session bean):
        private DefaultSelectItemsArray defaultListbox1Items = new DefaultSelectItemsArray();
        private DefaultSelectItemsArray defaultListbox2Items = new DefaultSelectItemsArray();
        private DefaultSelectItemsArray defaultListbox3Items = new DefaultSelectItemsArray();You will also want to create lists that hold the raw data like this:
    private List listbox1;
    private List listbox2;
    private List listbox3;In addition, you want to save the currently selected index so:
    private String list1SelectedIndex;
    private String list2SelectedIndex;
    private String list3SelectedIndex;You will then use the �setters� to these lists to fill your default items doing any conversion you need to perform. For example:
    public void setList1(List list1)
            //Build the defaultPatientListboxItems entries
            defaultListbox1tems.clear();
            Iterator listIterator = list1.iterator();
            while (list1Iterator.hasNext())
                String entry = (String)list1Iterator.next();
                SelectItem selectItem = new SelectItem(entry, entry);
                defaultListbox1Items.add(selectItem);
            this.list1 = list1;
        }Now to let JSF know that you are using the session bean to hold your data rather than the default list that Creator built, we will need to go in and modify the JSP (note that I think this step is being included in Creator 2�s IDE as something you will no longer have to code by hand).
    Here is example of how that will look:
    <h:selectOneListbox binding="#{PageName.listbox1}" id="listbox1" immediate="true" onchange="this.form.submit();"
                                    size="5" style="height: 184px; width: 234px" styleClass="centeredPageStyle" value="#{SessionBean1.listbox1SelectedIndex}" valueChangeListener="#{PageName.listbox1_processValueChange}">
                                    <f:selectItems binding="#{PageName.listbox1SelectItems}" id="listbox1SelectItems" value="#{SessionBean1.defaultListbox1Items}"/> Note in particular the value = SessionBean1.listbox1SelectedIndex and the value = SessionBean1.defaultListbox1Items.
    The first one is saying what the current selected entry is and the other is saying that the list that backs the listbox is called.
    Remember when I said that we wanted to autoselect an entry if only one entry existed inside of the listbox? Well, that is why we set the value = SessinBean1.listbox1SelectedIndex. Along with this, we need to modify a �getter� in our session bean to look something like this:
    public String getListbox1SelectedIndex()
            if(list1 != null && list1.size() == 1)
         //DO ANY CONVERSION NEEDED HERE
    //IN OTHER WORDS, IF YOUR LIST DOES NOT
    //HOLD STRINGS, THEN READ THEN OBJECT
    //FROM THE LIST AND GET THE STRING VALUE
    //FROM THAT OBJECT YOU USED TO ENTER
    //INTO THE LISTBOX
                ImageSet imageset = (ImageSet)list1.get(0);
                return imageset.getSetName();
            return this.list1SelectedIndex;
        }Now we have all of the data we need stored off, all we need to do is make sure that when the page bean�s constructor gets called, we �prime� the pump to make sure everything gets auto-selected.
    We can do that with something like this (placed inside of the page bean�s constructor):
    List listbox1List = sessionBean1.getPatientList();
    if (listbox1List != null && listbox1List.size() == 1)
                   String listbox1Value = (String)listbox1List.get(0);
                   sessionBean1.setListbox1SelectedIndex(listbox1Value);  //This does it
                   processListbox1Change();  //Do whatever you need to do in this case here
    }Well, that's all there is to it. Hope this helps!

    Hi Darrin,
    This is fantastic!!!
    A sample application by name "CoordinatedDropdowns" is also available. I am sure the sample application and your tutorial will be of great help to many Creator users.
    Cheers
    Giri

  • [Error running JSP portlet in JDeveloper

    I'm writing a JSP portlet with JDeveloper 9.0.3.
    The "index.jsp" works OK, and I can see the registration URL for my new provider.
    I deploy the application to Oracle9iAS 9.0.2.0.1 Application Server succesfully throught DCM servlet, register the new provier and I can run the portlet succesfully.
    But if I try to run the "pasa_parametroShowPage.jsp" inside the Jdeveloper, I get an HTTP 500 Error :
    java.lang.NullPointerException
         void htdocs.pasa__parametro._pasa__parametroShowPage._jspService(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
         [htdocs/pasa_parametro/pasa_parametroShowPage.jsp]
              pasa_parametroShowPage.jsp:12
    Line 12 is:
    Hello <%= pReq.getUser().getName() %>
    Thanks in advance.

    In order to successfully run, "pasa_parametroShowPage.jsp" must be called in a portal context - JDeveloper does not do this.
    Therefore, when called from JDeveloper, the PortletRenderRequest object is not present, hance the null pointer exception.
    You shouldn't attempt to run this JSP directly from with in jdev. You'll notice that if you point a browser directly at that JSP, you will get the same null pointer exception.
    If you need to debug this JSP in jdev, you can use a portal instance **or** the test harness (http://portalstudio.oracle.com/pls/ops/docs/FOLDER/COMMUNITY/PDK/TESTSUITE/PDKTEST/PDKTEST.ZIP)
    to fire http requests at JDeveloper's embedded OC4J.

  • Need some help in a JSP

    Hi all
    i'm new to jsp technolohie and i'm writing a jsp that sends an email on red hat linux
    i keep having theses errors .
    ps the first jsp is fine but its in the second one i have problems
    org.apache.jasper.JasperException: Unable to compile class for JSPNote: sun.tools.javac.Main has been deprecated.
    An error occurred between lines: 33 and 38 in the jsp file: /sending.jsp
    Generated servlet error:
    /jakarta-tomcat-4.0.3/work/localhost/_/sending$jsp.java:103: '}' expected.
    out.write(" \r\n \r\n \r\n \r\n\t \r\n");
    ^
    An error occurred between lines: 38 and 75 in the jsp file: /sending.jsp
    Generated servlet error:
    /jakarta-tomcat-4.0.3/work/localhost/_/sending$jsp.java:109: Statement expected.
    public void postMail( String recipients[ ], String subject, String message , String from) throws MessagingException
    ^
    An error occurred between lines: 75 and 97 in the jsp file: /sending.jsp
    Generated servlet error:
    /jakarta-tomcat-4.0.3/work/localhost/_/sending$jsp.java:146: Type expected.
    out.write(" \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n<h1> \r\n \r\nMessage sent successfully \r\n \r\n</h1> \r\n\t \r\n</body> \r\n</html> \r\n \r\n \t\t\r\n");
    ^
    3 errors, 1 warning
    could u take a look at my codes please so i can know what to do
    this is the first jsp in wich a compose the message
    <%@ page language="java" %>
    <%@ page errorPage="errorpage.jsp" %>
    <html>
    <head>
         <title>JavaMail compose</title>
    </head>
    <body bgcolor="#ccccff">
    <form METHOD=POST ACTION="sending.jsp" >
    <input type="hidden" name="send" value="send">
    <p align="center">
    <b><font size="4" face="Verdana, Arial, Helvetica">
    JavaMail Compose Message</font></b>
    <p>
    <table border="0" width="100%">
    <tr>
    <td width="16%" height="22">     
    <p align="right">
    <b><font face="Verdana, Arial, Helvetica">To:</font></b></td>
    <td width="84%" height="22">
    <% if (request.getParameter("to") != null) { %>
    <input type="text" name="to" value="<%= request.getParameter("to") %>" size="30">
    <% } else { %>
    <input type="text" name="to" size="30">
    <% } %>
    <font size="1" face="Verdana, Arial, Helvetica">
    (separate addresses with commas)</font></td></tr>
    <tr>
    <td width="16%"><p align="right">
    <b><font face="Verdana, Arial, Helvetica">From:</font></b></td>
    <td width="84%">
    <input type="text" name="from" size="30">
    <font size="1" face="Verdana, Arial, Helvetica">
    (separate addresses with commas)</font></td></tr>
    <tr>
    <td width="16%"><p align="right">
    <b><font face="Verdana, Arial, Helvetica">Subject:</font></b></td>
    <td width="84%">
    <input type="text" name="subject" size="55"></td></tr>
    <tr>
    <td width="16%"> </td>
    <td width="84%"><textarea name="text" rows="15" cols="53"></textarea></td></tr>
    <tr>
    <td width="16%" height="32"> </td>
    <td width="84%" height="32">
    <input type="submit" name="Send" value="Send">
    <input type="reset" name="Reset" value="Reset"></td></tr>
    </table>
    </form>
    </body>
    </html>
    this is the send.jsp to wich the first jsp post its data
    <%@ page language="java" %>
    <%@ page import = "java.io.*" %>
    <%@ page import = "java.net.InetAddress" %>
    <%@ page import = "java.util.Properties" %>
    <%@ page import = "java.util.Date" %>
    <%-- @ page import = "javax.mail.* --%>
    <%-- @ page import = "javax.mail.internet.* --%>
    <%@ page errorPage="errorpage.jsp" %>
    <html>
    <head>
         <title>JavaMail send</title>
    </head>
    <body bgcolor="white">
    <%
    String to= request.getParameter("to");
    String from= request.getParameter("from") ;
    String subject= request.getParameter("subject") ;
    String emailBody= request.getParameter("text") ;
    %>
    <%
    public void postMail( String recipients[ ], String subject, String message , String from) throws MessagingException
    boolean debug = false;
         //Set the host smtp address
         Properties props = System.getProperties();
         props.put("mail.smtp.host", mailhost);
         // create some properties and get the default Session
         Session session = Session.getDefaultInstance(props, null);
         //session.setDebug(true);
         session.setDebug(debug) ;
         // create a message
         Message msg = new MimeMessage(session);
         msg=emailBody ;
         // set the from and to address
         InternetAddress addressFrom = new InternetAddress(from);
         addressFrom =From ;
         msg.setFrom(addressFrom);
         InternetAddress[] addressTo = new InternetAddress[recipients.length];
         addressTo = To ;
         for (int i = 0; i < recipients.length; i++)
         addressTo[i] = new InternetAddress(recipients);
         msg.setRecipients(Message.RecipientType.TO, addressTo);
         // Setting the Subject and Content Type
         msg.setSubject(subject);
         msg.setContent(message, "text/plain");
         Transport.send(msg);
         msg.setSentDate(new Date());
    %>
    <h1>
    Message sent successfully
    </h1>
    </body>
    </html>

    Hi,
    Take a look at this page. It has a MessageBoard that also links to a very simple mailing program. It's as basic as you can get, but should help.
    http://cswww.essex.ac.uk/TechnicalGroup/TechnicalHelp/Intro.html
    best,
    kev

  • HTML Comments in a JSP Document

    I am writing a JSP Document that has a number of comments. Some I want to be server-side such as version history and some I want to be client-side.
    Using a JSP page this is easily achieved using JSP comments <%-- JSP comment for server-side --%> and HTML Comments<!-- HTML comment client-side -->.
    Using XML syntax a number of things are apparent:
    1. There is no XML equivalent of a JSP comment (this has been well doc'd for a long time).
    2. In the Java EE tutorials the recommended alternative to a JSP coomment is a HTML comment.
    3. Using HTML comments in a JSP document the web container omits these in the page output - and so they are server-side only just like a JSP comment.
    Code Snippet:
    <template xmlns:jsp="http://java.sun.com/JSP/Page" xmlns:c="http://java.sun.com/jsp/jstl/core" version="1.2">
    <!-- this comment will not appear in the generated source on the client browser -->
    </template>
    <!-- JSP fragment for no caching policy -->
    So, my question is how do I generate a client-side comment in a JSP Document?
    Thanks
    Edited by: DJT on Mar 3, 2008 4:28 AM
    Edited by: DJT on Mar 3, 2008 4:30 AM

    I found this ....
    http://www.javaworld.com/javaworld/jw-07-2003/jw-0725-morejsp.html
    One significant disadvantage of JSP documents is that no XML-compliant version of JSP comments exists. A JSP document developer can use client-side (HTML-/XML-style) comments or embed Java comments in scriptlets, but there is no JSP document equivalent to <%-- -->. This is a disadvantage because the other two commenting styles JSP documents can use have their own drawbacks. You can see the client-side comments in the rendered page using the browser's View Source option. The Java comments in scriptlets require placing Java code directly in the JSP document.
    So try to embed the HTML comment inside scriptlet tags...
    <%
    <!-- HTML comment here -->
    %>

  • How to pass a command line argument to a jsp file...

    Hi guys,
    I'm writing a jsp file in which I have some java codes. I want to pass some command line arguments to that jsp file. In other words, I have some files located somewhere on my C drive and I want to pass the path to these files to my jsp file. How can it be done? I have never done before.
    Any suggestion will be very hepful...
    Thanks....

    I dont know if I truly understand your problem...
    For instance, when you place the url of your jsp you can add, at the end some parameters. For example:
    http://myserver/myapp/myjsp.jsp?MyParameter=C:\Temp\JavaTutorial.html
    In your JSP, you can place this code on a scriplet to get the value:
    String path = request.getParameter("MyParameter");
    Hope it helps.

  • Multiple function signatures in JSP custom tag file

    I'm writing a jsp .tag file and I've encountered the following problem. I have those two functions :
    private void iterateThroughChildElements(Element element)
         for (Iterator i = question.getElements().iterator(); i.hasNext(); )
              this.parseAndDisplay( (Element) i.next() );
    private void parseAndDisplay(Question question)
    private void parseAndDisplay(Answer question)
    (......)Both Answer and Question objects are elements but I get an error from the compiler which says that no correct signature was found for the parseAndDisplay function.
    What could be the problem ? Do I have to cast the objects according to a instanceof comparaison ??

    There was an error in my code, it is as follows :
    private void iterateThroughChildElements(Set elements)
         for (Iterator i = elements.iterator(); i.hasNext(); )
              this.parseAndDisplay( (Element) i.next() );
    }

  • Beans through jsp

    hi,
    i' m trainee developer and working in struts. i'm totally novice in this regard. my pl asked me to develop an application on struts. i'm getting problem while using bean through jsp. i'm writing code:
    <jsp:useBean id="myBean" class="MyBean" type="MyBean" scope = "session"/>
    the error is:
    cannot resolve symbol
    symbol : class MyBean
    location: class org.apache.jsp.confirm_jsp
    MyBean myBean = null;
    ^
    total 3 errors associated with it. MyBean class is located in WEB-INF/classes
    can any one help me out?

    put your bean in a package and put that package under the WEB-INF/classes directory. Then use the fully qualified class name for the jsp:useBean:
    //in the bean
    package net.thelukes.myprog.beans;
    //the jsp:useBean
    <jsp:useBean id="myBean" class="net.thelukes.myprog.beans.MyBean" scope="session"/>

Maybe you are looking for

  • Capture "Preview Disabled" and unable to "Capture Now"

    Okay so I don't think I'm the only one but figgured I'd post just to see what the status is. Today I went to capture some plain ol' DV footage from my Panasonic PV-GS500 minidv camcorder and was unable to... sorta. If I try to capture I get the messa

  • Adding item data in Product tab for sales contract (crm_order_maintain)

    Hi, can I use crm_order_maintain to add line items under the product tab for a sales contract while creating or modifying an order. Is there any sample code to add the line items, I could look at.  I tried calling this FM from my custom tab and then

  • Raising Faults in a Sync Scenario.

    Hello PI experts, I really need an answer to this question, most of the answers i find out about this is all negative. 'PI can't do that w/o BPM' Scenario: SOAP<->PI<->RFC(sync) Problem: in case of application specific errors, RFC response will have

  • How to create groups and add users?

    Hello, I have created 3 groups as Portal_Admin and added 2 users for each group. When I am trying to grant permissions to these groups to the Applications owned by Portal30( I have logged in as portal30 at this point), I am unable to see these groups

  • HT203482 OS X could not be installed - instructions not working

    When I click on 'partition', I cannot resize the blue portion because no blue portion appears and instead the message 'this partition can't be modified' appears. What should I do?