About JSP & servlet -

Hi,
please help....how to set the session variable in servlet and pass that to JSP page?
Thanks!

Hi,
In Servlet, you can use the request.getSession(boolean) for getting the Session. For more information, please see the Java Documentation.
This session is available by default in the JSP page. For using it just use the 'session' object directly. It is already defined.
Hope this helps,
Rajat,
OTN Team@IDC

Similar Messages

  • Need Suggestion about JSP/Servlet OR JSF2.0

    I am new to Java and working on it as fast as possible. Got 5+ years experience in ASP.NET C#. I have covered basics of Java and now want to jump into web development by making a project by converting one of my ASP.NET project.
    I have explored Servlet/JSP and JSF2.0. Want to learn only one from them and put all my energies in it. I find JSF more robust, clean and easy to use with templating etc . I am doing all this so that I cover most of the things to complete one full project and try to find a job as starter in Java.
    Now my questions
    As a starter job in Java what things should I know?
    Should I learn Servlet/JSP even if I am good at JSF (suppose)?
    Do companies still need skills in Servlet/JSP or they are adopting JSF?
    Thanks

    Prateek wrote:
    first i would like to asked you one question why you want to change your technology ? you have over 5+ year experience in Microsoft technology .java and microsoft both are programming language .i recommend you if you have 5+ year experience then you do not need to switch your technology . this is one things .but i am sure it is not a big deal for you to switch the technology .
    see jsf and jsp both are based on the servlet .main things is that you have to learn servlet first .Why wouldn't you want to switch your technology? Java barely existed when I started my career. If I had stuck with only the language I needed for my first job, I'd have very few jobs available to me now. If one technology was good for everything, then other technologies wouldn't be invented--we would have stuck with the first technology. Different languages have different advantages (and different disadvantages). You should learn what you need for the tasks you are given, as well as learn what you need for the jobs that are available. If there are fewer jobs in technologies you already know, you should learn a new one. Or, you can learn a new one just because you want to expand your horizons, or any other reason you feel like.

  • Questions about Java Servlets and JSP

    Hi,
    I'm a confident Java Programmer (and really enjoy using this language) but am very new to Java servlets and Java Server Pages.
    I have previously worked with Perl on my web projects (simple 'league' style voting pages). I read in my 'Core Java' book that I should no longer use perl or even cgi.
    I need to know more about Java servlets and Java Server Pages so I can make the switch to a 'real' programming language.
    I have a few questions:
    How should I start to learn JS and JSP?
    How applicable will the java knowlegdge I have already be?
    Are JSP common on the world wide web?
    What tools do I need to start? (I currently develop in JBuilder and have Java 1.4.1 Standard Edition)
    Is it likey my web host (and others) will support JSP?
    Thank-you very much for helping a novice get started,
    Regards,
    Paul

    Hi, Steve ...has to be frustrating! But do not despair.
    Let's suppose the servlet it's named MyServlet on package org.servlets
    WEB-INF should look:
    WEB-INF
    classes
    org
    servlets
    MyServlet.class
    web.xml
    web.xml file should have this two declarations:
    <web-app>
      <servlet>
        <servlet-name>MyServlet</servlet-name>
        <servlet-class>org.servlets.MyServlet</servlet-class>
      </servlet>
      <!-- other servlets -->
      <servlet-mapping>
        <servlet-name>MyServlet</servlet-name>
        <url-pattern>/MyServlet</url-pattern>
      </servlet-mapping>
      <!-- other servlets mappings -->
    </web-app>Now, once the container starts (Tomcat?), you should be able to see that servlet in:
    http://localhost:8080/[my-context/]MyServletAnd what my-context is? The web application context. This string should be empty if your're deploying to the root context, otherwise should the context name. In Tomcat, deploying to root context defaults to using webapps/ROOT.
    Sorry for my English, but I felt the need to answer your request. I hope it helps despite my writing.

  • Question about domain name/JSP, servlets

    I have a web host which publishes my pages, say www.zzz.com. I want to use JSP/Servlets on my machine which is using Apache Tomcat. Here's the problem, if I link a JSP/Servlet from www.zzz.com, the user will see my IP, i.e. 37.28.18.102/servlets/Calculations
    Is there a way where the people's browser's URL text field will always be www.zzz.com even if the page is located on my server?

    Try using Frameset where top frame is always www.xxx.com and child frame can be anywhere

  • Is there any JSP/servlet opensource project like phpMyAdmin?

    Is there any JSP/servlet opensource project existed which is designed to manipulate the database MySQL such as phpMyAdmin?
    I would like to gain the source code and reference to its design pattern.

    I don't know about PHPMYAdmin but MySqlAdmin can do any job you need
    http://www.skillipedia.com

  • Jsp,servlet,bean question,please help

    The Tomcat Web server set up like this.......
    The directory structure is
    e:/sampleapp/WEB-INF/classes
    /lib
    And the web.xml is in the WEB-INF for the use of ay potential servlet.
    The basic understanding is that all the .java files go into the WEB-INF directory and the .class files go into the classes directory.
    All the .jsp files go into the sampleapp directory.Till here is correct I feel.
    Now for my qustion......
    I plan to use jsp,servlet and beans for a potential web application...,where do all these files go?,just the same as above or is there a difference.
    Hope that I have given a reasonable explaination to my question.
    Thanks for any replies
    AS

    All of your compiled servlet and java bean (java
    classes in general) will be placed into the following
    directory (under a directory structure matching the
    java package they are in):
    e:/sampleapp/WEB-INF/classesAll of your .jar files that are used as libraries (not
    your .jar files for applets):
    e:/sampleapp/WEB-INF/libAll of the rest of your JSP files, javascript files,
    HTML files, JAR files, images files, etc. will go into
    the following directory:
    e:/sampleappYou must make sure you put your sampleapp directory
    where tomcat can load it. Or use the admin tool to
    load it. If you make a .WAR file with a corresponding
    web.xml file in it, it will simplify loading it into
    tomcat. It also will help you do your servlet
    mappings, etc. I hope this helps.Thanks for your timely response.To add to it,let me tell you.
    The <b>bean</b> files are put into a package right,so they should be put into the WEB-INF/classes/<package name>
    What about The <b> servlet </b> files...... they are just put into the WEB-INF/classes/ directory????
    Kindly let me know.
    Thanks
    AS

  • JSP- Servlet-- Bean-- JSP how to implement

    I have problem.
    My JSP will take a emplyee id .
    Now I want to show all the values regarding that employee in a JSP(JSP form) from the DB(Oracle).
    So Iam planning like
    JSP-->Servlet-->Bean-->JSP
    So my doubts are.
    1. Is it correct approach
    2.If it is correct then which part of the flow connects to DB and stores the value before putting to JSP.
    Iam using Tomcat 4.31
    Plz help me

    I have problem.
    My JSP will take a emplyee id .
    Now I want to show all the values regarding that
    employee in a JSP(JSP form) from the DB(Oracle).
    So Iam planning like
    JSP-->Servlet-->Bean-->JSP
    So my doubts are.
    1. Is it correct approach
    2.If it is correct then which part of the flow
    connects to DB and stores the value before putting to
    JSP.
    Iam using Tomcat 4.31
    Plz help meHI
    What you are probably proposing is an MVC design pattern. I wonder if u have heard of the struts framework. Sruts uses MVC design pattern wherein the servlet u are talking about acts as a controller(C) and the bean acts as the model(M) .The JSPs present the view(V). Hence the name MVC.
    Your approach is right. First get the employee ID from the jsp and get the corresponding data from database(This logic u implement in the servlet). Then save the fetched data in a bean so that the result jsp can fetch data from it.
    Now this is not a strict MVC approach.
    Learn more about struts. It presents a much more cleaner solution.

  • Newbie question about loading servlets on tomcat

    I have what is probably a very basic question about loading simple servlets on to tomcat to test its installation. I have followed instructions from numerous tutorials to the letter but still I can't get it to work.
    I have installed tomcat on win2k in c:\tomcat. I set up the jdk, environment vars (JAVA_HOME, CATALINA_HOME, TOMCAT_HOME) which all point at the correct dirs. I can compile a servlet without errors. I can also place a test jsp and html file into the root directory and they both work fine.
    However, now I am trying a test servlet and no matter what I do it gives me a 404. I have a servlet class file called "HelloServlet.class" which I placed into the %install_dir%\webapps\ROOT\WEB-INF\classes directory. I try to reference it using this url:
    http://localhost/servlet/HelloServlet
    Tomcat is configured to use port 80 and has been restarted after adding the servlet class file. Does anyone have a clue why this is not working for me?
    Many thanks
    Marc

    You have to add in the web.xml file that it is in the WEB-INF dir, the information about your servlet. An example:
    <web-app>
    <servlet>
    <servlet-name>HelloServlet</servlet-name>
    <servlet-class>HelloServlet</servlet-class>
    </servlet>
    <servlet-mapping>
    <servlet-name>HelloServlet</servlet-name>
    <url-pattern>/HelloServlet</url-pattern>
    </servlet-mapping>
    </web-app>

  • I need info about JSP!

    Hi,
    I have some simple questions for jsp "experts". is it possible to get a version of jsp for free or how much does it cost?
    how safe is it to use in a big network of computers?
    Which databases does JSP support?
    please, please, answer as soon as possible!! =)
    thanks
         /jenny

    There are many JSP/Servlet server products which are free. These include Tomcat, Resin, JBoss, etc. These are all great for development-level work or small Net apps). If you need to implement a larger J2EE solution you will definitely want to look into one of the retail server products. These range from the very inexpensive (like Allaire's JRun) all the way up to expensive (like BEA's WebLogics) and everywhere in between. Just depends on your needs, budget, and requirements.
    Extremely safe. Especially when you look at the alternatives/competition (i.e., M$ COM/DCOM/ASP).
    Java supports just about every RDBMS on the market right now (you will run into difficulties with M$ SQLServer, but there are options). There are also drivers available for many legacy data sources. The subset of java which deals with database access is named JDBC; you may want to research this a little. Here is a link to the available JDBC drivers search page:
    http://industry.java.sun.com/products/jdbc/drivers

  • Can somebody explain to me how JSP, servlets, ASP work within Sun's server

    Ok, I'm only beginning to get a grip of how all this works. And I have a lot of questions and confusion.
    1.) The server that comes with J2EE, what is that server? Is it an app server that runs only servlets and JSP, with some Web server stuff so it can output some info? Is it a stripped down version of TomCat? I am having a lot of trouble with the J2EE server (the one that comes with the SDK), and that is why I'm asking, maybe I don't need it. But I really want to learn JSP's, JScripts, and Beans. How else can I go about doing that, other than all out Tomcat.
    2.) Also can I run Servlets on Microsft's IIS on a Windows 2000 machine? Do I need a special API to run servlets, or JSPs?
    So how I see it, and again, I am a newbie at this. Machines that host a website, above all needs a web server. let's say most people use Apache, and they want to run it in Linux, becuase they want to be hackers. So then do they also run Tomcat, or IIS, or Coldfusion, or a million other servers in tandem on the same machine, so that they can handle ASP, JSPs, servlets, .cmf, etc.? or do they separate the app server from the webserver and then do some sort of linking? if somebody can direct me to how all this stuff works, I would greatly greatly appreciate it.

    Sounds like you need to read the J2EE spec as well as
    the servlet and JSP specs. It helps to glance through
    sections you are interested in.
    Ok, I'm only beginning to get a grip of how all this
    works. And I have a lot of questions and confusion.
    I think for a newbie, deploying your jsp's and servlets
    to a J2EE compliant app server can be quite a headache.
    You might want to concentrate on tomcat, which does servlet
    and jsp.
    Some app servers provide a http connector for most common web servers.
    I think tomcat has a IIS connector. In this case IIS would serve static html as well as its own stuff, other things like servlets and jsp go to tomcat. I am unsure about this as I mostly use tomcat in standalone mode. You can run tomcat on windows, as it is written in java.
    >
    2.) Also can I run Servlets on Microsft's IIS on a
    Windows 2000 machine? Do I need a special API to run
    servlets, or JSPs?

  • About jsp tags..............

    Pls help
    I am studing about JSP
    if we write code in scriptlet tag i.e. < % %>
    code goes into service() method of servlet ,which is automatically created by jsp Engine
    if we write code in declaration tag i.e. <%! %>
    code goes outside service() method of servlet ,which is automatically
    created by jsp Engine means at class level.
    is their any tag so that jsp code goes into init() method of servlet ,which is automatically created by jsp Engine for that jsp

    simple and straight u need to code init() method using <%! %> tags.. but in case JSP it has to be jspInit() method.
    The jspInit method is called by the container once and only once for a servlet instance. As you might guess from its name it is used to do initial once only setup such as getting resources and initialising variables that are used in the JSP page. The jspInit method can be overridden within a JSP page with code like the following.
    <%!
    public void jspInit(){
    /*getServletConfig is inherited */
    ServletConfig config= getServletConfig();
    %>REF : http://www.examulator.com/moodle/mod/resource/view.php?id=380
    REGARDS,
    RaHuL

  • JSP/Servlets on ColdFusion MX 7

    I have a customer that needs to run a JSP/Servlet forum
    software. I dont want to have to build a server using Apache Tomcat
    when I have a perfectly good Windows server running ColdFusion MX
    7. Just one more headache to worry about. Currently, I have
    ColdFusion MX 7 running IIS 6.0. I did not install the JRUN web
    server. Can I rerun the install to put JRUN on the server to run
    the servlets? Do I need to build another Windows server and install
    JRUN without IIS? Not sure what to do here. Any help would be
    appreciated. Thanks.
    Don Seibert
    SeiberSpace Technologies, LLC
    www.seiberspace.net

    JSPs and servlets will run directly inside CFMX7 enterprise,
    but not standard. You can use your standard webserver and do not
    need to activate the JRun webserver.

  • Menu item in Jsp/Servlet

    Hi experts, when you're using Jsp/Servlet to implement the front-end web application, what options do you have for implementing some menu dropdown?
    Is awt or swing can be used for that purpose?
    How would you go about the layout management issue?
    Thanks, and your reponse is appreciated

    I guess You are looking for a solution in JSP/Servlets. Here is my program that might be help ful to you. This program will bring a drop down list that fetches the values from the database.
    <table cellpadding=4 cellspacing=2 border=0 align=center>
    <TR>
    <TD><B>choose Code</B></TD>
    <TD valign=top>
    <!-- this code is to generate the list of Codes-->
    <% String userId =(String) session.getValue("userName"); %>
    <%
    Connection con = null;
    Statement stmt = null;
    ResultSet rs = null;
    String uId;
    String returnString="";
    String null_value="";
    try {
    Class.forName("oracle.jdbc.driver.OracleDriver");
    con = DriverManager.getConnection("jdbc:oracle:thin:@serverName:1521:localHost", "scott", "tiger");
    if (con == null) {
    System.out.println("Connection not found");
    stmt = con.createStatement();
    con.setAutoCommit(false);
    String sql= "select code from example_list where user_id='"+userId+"'";
    rs= stmt.executeQuery(sql);
    %>
    <select name="alcList">
    <%String aString;
    rs= stmt.executeQuery(sql);
    while (rs.next()) {
    %>
    <option value="<%= aString = rs.getString("code") %>">
    <%= aString %></option> <%}%></select><%
    con.commit();
    //returnString= true;
    } catch(SQLException sqlex) {
    sqlex.printStackTrace();
    //return returnString;
    } catch(Exception ex) {
    ex.printStackTrace();
    } finally {
    stmt.close();
    con.close();
    stmt = null;
    rs = null;
    con = null;
    %></TD>
    <TD align=center>
    <INPUT TYPE=submit SIZE=30 VALUE="Submit"></TD>
    </TR>
    </Table>
    </FORM>
    </BODY>
    </HTML>if this doesn't answer your problem, Please post your question exactly. May be I can help you out.
    Good Luck.
    -Sreekanth varidhireddy

  • Clean URLs with JSP/Servlet

    Hello. I've found some information on how to setup clean URLs for php, but none for JSP/servlet. Hopefully some one can help. Here's what I mean by 'clean URL':
    http://mydomain/employee.jsp?employeeID=1232
    becomes
    http://mydomain/employee/1232
    And, in that second example, the container would dispatch all requests for /employee* to some JSP/servlet. I don't care if the 'clean URL' has to have an extension or not (e.g. mydomain/employee.jsp/1232) although I would prefer to also remove the JSP extension.
    Additionally (if some one has experience with this need): how do I then access the final part of the URL supplied by the client? In other words, how would 1232 be available to the destination JSP/servlet? Does the container convert it into a parameter, i.e.:
    1) client sends request for "mydomain/employee/1232"
    2) container delegates request to "mydomain/employee.jsp?1232"
    Finally (sorry about the length), I don't have access to top-level config files for this site (it's personal use, although I'm pretty familiar with java APIs from my job), so, ideally, I'd like a .htaccess level solution, where the container can just re-route to a JSP.
    If any one has some suggestions, I'd GREATLY appreciate it. Thanks for your time. Take care.

    ...Just occurred to me- this hosting company is NOT using Tomcat. They use resin.
    Thanks.

  • Best way to see changes done to jsps/servlets/ejb/xmls in EAR

    I am using iPlanet app server with iPlanet web server. Everytime i make any change jsp/servlet/ejb i have to redeploy whole ear application again. This takes a long time. Even when i use the "iasdeploy redployapp " command to deploy, it takes same amount of time as it takes for the orignal deployment.
    So Is there any way to decrease the amount of the time it needs for me to re-deploy the applications when slight changes are made to application. I would really be thankful to anybody who can help me.

    Hi,
    I am facing this problem with a simple EAR file also. It does not contain any EJBs.
    It has just JSPs, XML, and JAVA Classes.
    The file size is about 481Kb.
    Earlier this used to get deployed using the "iasdeploy" command within 1 minute.
    Now it is taking more than 5 minutes to deploy the EAR file.
    I am using the following command :
    iasdeploy deployapp -verbose XYZ.ear
    The same holds true for the "iasdeploy removeapp -verbose XYZ.ear" also.
    Please help.
    Thanks,
    Samar

Maybe you are looking for

  • Error in generating a new XSL Transformer from large xslt File

    Good day to all, Currently I am facing a problem that whenever i try generating a Transformer object from TransformerFactory, I will have a TransformerConfigurationException threw. I have did some research from the net and understand that it is due t

  • Can I talk to a real person?  it is complicated.

    long story...but i have a "new" iphone 4 and synced photos.  it came up on iphone under albulms as "photo library" and "pictures from."  Problem #1: duplicate photos & problem #2 - cannot delete them! i sent to settings and general  and usage & delet

  • Is there anything like Disk Doctor and Speed Disk for Leopard?

    Is there any way to do ordinary "maintenance" on a computer using Leopard? Is there any need to do anything? I've had this computer for 8 months now, and I feel kind of guilty not doing anything like running disk doctor for so long!

  • Frustrating syntax error:cfqueryparam

    I must be brain dead. I have been looking at this code for about 45 minutes trying to figure out where the syntax error is. I think it is in one of the "," but I have rearranged them so many times I am going bonkers. Can someone find where my error i

  • What is JHeadstart and how it is different from Jdeveloper

    Hello everbody I am new to JHeadstart but iam quite aquinted with Jdeveloper 10.1.3, so can any body please tell how JHeadstart is better than Jdeveloper and what extra thing can we do with it