Executing an executable from a servlet or a JSP

Is it possible to call an executable from a servlet. Say I have a client server application and I want to start the client application from a servlet. What is the best way to do that?
I know normal Java applications can use the Runtime to run an executable. Can a servlet do the same? What are the security implications, considering that the servlet will be accessed from a browser?
Thanks for your help.

A servlet is executed on the server, not the client. The client receives a response from the servlet which is usually plain text formatted as HTML and/or javascript.
So can a servlet use the Runtime class? Sure, but on the SERVER, not on the client. Hence, the executable will need to be on the webserver, not on the client machine and it will execute on the webserver, not on the client.
Maybe, your HTML formatted response can include an <applet> tag to trigger the browser to download an applet that may have access to call an executable. Maybe a trusted applet?

Similar Messages

  • How to display outsream from a servlet in a JSP

    I wrote a jsp file to call a Servlet, then want to display the result from the servlet in another jsp file. Anyone can give me possible solution or an example to illustrate it.
    Many thanks in advance.
    the file that call servlet in a jsp is as follow
    <form method="POST" action="myservlet">
    <table>
    <tr>
    <th align="center" colspan="2">
    Enter The query words
    </th>
    </tr>
    <tr>
    <th align="right">query words:</th>
    <td align="left">
    <input type="text" name="querywords" size="60">
    </td>
    </tr>
    <tr>
    <td align="right">
    <input type="submit" value="Search">
    </td>
    <td align="left">
    <input type="reset" value="Reset">
    </td>
    </tr>
    </table>
    </form>
    ............

    I would suggest that you use the Servlet to retrieve the data you are after and store it in the session. Then forward the user onto the JSP page where it can retrieve the object from the session and present it to the user in a formatted view.

  • How do I Display a string from a servlet into a JSP Page???? NEED HELP!!!!

    Hi guys,
    How do I Display a string from a servlet into a JSP Page...
    Ive tried so many bloody things!.....
    Simply.
    I get text from JSP. The servlet does what ever it does to the string.
    Now. Ive create sessions and bean things,.... how the hell do I display it in a text box... I can display on the screen.. but not in the text box.!!!
    please help!!!

    hmmm, I dont really like using JSP programming, u should be using JAVA..
    the way to do it is:
    Call and cast to the bean like this:
    <%@ page import="beans.*" %>
    <% //cast to bean get request create object
    userNameBean u= (userNameBean) request.getSession().getAttribute("userNameBean");
    then... all you do is call it like this:
    <input type="text" name="firstName" value="<%= u != null? u.getFirstName(): "" %>">
    this is the real programmers way,,,
    chet.~

  • Challenge forwarding from a servlet to a JSP

    Redirecting information from a servlet to a JSP
    Hello Everyone,
         I am processing the contents of a html form using a servlet. After processing the
    information received and storing it into a javabean I am trying to pass control onto a jsp for
    display. At this stage the jsp does not display as desired due to a URL challenge. The URL
    which references my jsp is:
    http://localhot/ferngully/prefset.jspThis url has been designated to the jsp page 'prefset.jsp' by the application specific web.xml
    file (...I am using Tomcat 5!), the relevant contents of which follow:
    <servlet>
         <servlet-name>PreferenceSet</servlet-name>
         <jsp-file>/prefset.jsp</jsp-file>
    </servlet>
    <servlet-mapping>
         <servlet-name>PreferenceSet</servlet-name>
         <url-pattern>/ferngully/prefset.jsp</url-pattern>
    </servlet-mapping>If I access the page with the afore mentioned URL it displays correctly. However the URL which
    is returned to the browser after the servlet has forwarded control to the JSP is:
    http://localhost/ferngully/ferngully/PreferencesThe following form markup is used to access the servlet:
    <form name="form1" method="post" action="ferngully/Preferences"> I know that I have mapped the servlet correctly because the servlet performs it's programatic tasks happily :)
    I am using code within the servlet to forward control to the JSP, and I believe that this is the crux of my challenge.
    The code for the servlet is listed below.
    package userpreferences;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.io.*;
    import java.util.*;
    public class PreferencesServlet extends HttpServlet
         public void init(ServletConfig config) throws ServletException
              super.init(config);
         public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
              doPost(request, response);
         public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
              String url = "/prefset.jsp";
              ServletContext servCont = getServletContext();
              RequestDispatcher reqDispatch = servCont.getRequestDispatcher(url);
              reqDispatch.forward(request, response);
    }I believe that the above highlighted code section is responsible for my challenge. I have tried changing the String url to "/ferngully/prefset.jsp",
    however there was no improvement in functionality.
    Can somebody please explain to me how I can go about directing the control of this process from the servlet to the jsp correctly? Particularly
    how I can go about making the url returned to the client correct for accessing the jsp page? Do I need to delete the mapping entry for the
    jsp page in web.xml? I am new to servlets & jsp so any help will be much appreciated.
    Thanks
    Kind Regards
    Davo

    3. >The following form markup is used to access the servlet:
    <form name="form1" method="post" action="ferngully/Preferences">Question 1:
         why do you specify your contextname in action attribute again ?
         General funda about urls:
         When you have an index.html loaded through http://localhost/index.html, then a link in that html whose url is,
         1. say, preferences.html (no forward slashes preffixed or suffixed) would load the html from the same folder.
         2. say, /ferngully/prefences.html, would attempt to load a html from the ferngully folder that is a sub-directory
    of your web-application
         3. say, /ferngully/prefences.jsp, would attempt to load a html from the ferngully folder that is a sub-directory
    of your web-application
         When you have a servlet whose url-pattern is set to intercept requests, it would intercept requests that have that
    pattern it is defined to intercept in web.xml (for example all the above requests in 1,2 and 3 would be intercepted
    by a servlet whose pattern is ferngully/*)
         Now if your action is not a specific resource (.jsp or .html), something like /preferences, this would map to a url
    /ferngully/preferences. (for which a resource should be defined in web.xml - either a servlet or a jsp)
    However the URL which is returned to the browser after the servlet has forwarded control to the JSP is:
    http://localhost/ferngully/ferngully/PreferencesTell us the url of the original html
    I know that I have mapped the servlet correctly because the servlet performs it's programatic tasks happily :)Tell us the url-appetrn of the servlet that intercepted your request
    Particularly
    how I can go about making the url returned to the client correct for accessing the jsp page?The url in the browser is always the request url, you cannot change it to the url of the jsp even which rendered the page
    through a fwd from the servlet.
    Do I need to delete the mapping entry for the
    jsp page in web.xml?Not necessary. You can access the jsp directly from the servlet while forwarding by
    1. specifying the exact path to the jsp. For example if the jsp is under a folder called jsps, your request dispatcher
    url ought to be /jsps/prefset.jsp
    2. specifying the jsp's url-pattern as specified in web.xml
    Questions Contd
    2. Why does the url pattern have to have a .jsp suffixed.
    From your code
    <url-pattern>/ferngully/prefset.jsp</url-pattern>It could equally well have been
    <url-pattern>/ferngully/prefset</url-pattern>And then your servlet would have to forward it to ("/ferngully/prefset")
    2. Your jsp-file mapping is in this form
    <jsp-file>/prefset.jsp</jsp-file>This assumes that the jsp is in the top-level folder of your web-application and not under
    any sub-directories. Correct ?
    cheers,
    ram.

  • Executing .sh files from a servlet

    Hi,
    Please clarify me on executing a .sh files from a servlet. or from a java class.
    Thanks.

    Runtime rt = Runtime.getRuntime();
    rt.exec(" <u r shell script file >");
    this works fine in java class... i dont exactly know weather it works in servlet or not.... check it out....
    jogesh

  • Session is lost when going from a servlet to a jsp

    Any help would be greatly appreciated.
              I can sucessfully go from my jsp page to the Servlet. When in the servlet I have a service method where I place the information from my form on the jsp on a bean. Then I do a session.setAttribute("aBean", aBean) to place the bean in the session. Then do a req.sendRedirect("my.jsp"). Watching it in the debugger, when we leave the servlet our session is cleared and when we do a jsp:usebean to get the bean session from the session it creates a new bean so all the information is gone that was there before. here is my usebean tag where we are getting it from scope,
              <jsp:useBean id="aBean" scope="session" class="com.MyBean"></jsp:useBean>
              Thanks, Trucker

    <jsp:useBean name="helper" scope="session" class=".."/>
              <jsp:useBean name="helper" scope="session" type=".."/>
              ·class="package.class"
              Instantiates a bean from a class, using the new keyword and the class constructor. The class must not be abstract and must have a public, no-argument constructor. The package and class name are case sensitive.
              ·type="package.class"
              If the bean already exists in the scope, gives the bean a data type other than the class from which it was instantiated. The value of type must be a superclass of class or an interface implemented by class.
              If you use type without class or beanName, no bean is instantiate
              In your case you already instantiated the bean “com.MyBean” in servlet and you set bean in session scope. But you are not accessing that bean from servlet. Instead of that you are crating a new bean instance by using class attribute of <jsp: useBean>. So if you want to access the bean already created in servlet you should use type attribute instead of class in <jsp: useBean>. So you have to change your code as follows.
              <jsp:useBean id="aBean" scope="session" type="com.MyBean"></jsp:useBean>
              Then you will not lose the bean created in servlet.
              - Navaneeth

  • How can a user scroll the resultset obtained from a servlet in a jsp page?

    Actually i am having a page where user has to select company name and for tht i am providing him with a button, and on clicking tht button a
    new search page is provided , and on mentioning the search criteria ,a servlet is fired which returns a list of companies(tbasically i am creating a session object of resultset type which stores the companies name), now the servlets again goes back to search page, and here i want 2 display the company names, i am able to display company names in my search page , but now i want my user to select one of the companies from tht servlet.
    for tht i need to tap the onMouseOver function of java SCript, C
    Can any one tell me how to write code for tht
    Thanking in Advance

    see https://addons.mozilla.org/en-US/thunderbird/addon/send-later-3/

  • Trouble forwarding request from a servlet to a JSP in OAS 4.0.8.1 on NT

    The OJSP release notes state that:
    "Servlets and JSP cannot coexist as the same application" and "Requests cannot be passed between two separate applications."
    Does this mean that my attempts to use the
    the servlet RequestDispatcher to forward a request to a JSP are futile? If so, is this a problem that will be fixed in the future? I would like to use this feature!
    This is the code (based on a sample from Sun's JSWDK 1.0.1) that doesn't work:
    servletToJsp.java
    import javax.servlet.*;
    import javax.servlet.http.*;
    public class servletToJsp extends HttpServlet {
    public void doGet (HttpServletRequest request,
    HttpServletResponse response) {
    try {
    getServletConfig().getServletContext().getRequestDispatcher("/jsp/jsptoserv/hello.jsp").forward(request, response);
    } catch (Exception ex) {
    ex.printStackTrace ();
    I am able to use the <jsp:forward page="/servlets/servletToJsp" /> directive to go from a JSP page to a servlet (across two OAS Applications) and I also can forward a request via the dispatcher from one servlet to another in the same OAS application.
    Any help in this area would be appreciated. Thanks.

    I'm using OAS 4.0.8.1
    You mean servlet to JSP does not work and JSP to servlet works for you????Yes - but I've only tried very simply examples.
    That's different from my understanding. If you are using OAS 4081, both cases should not work.
    The problem you mentioned will be fixed in future release of OAS.That's good to know - thanks!
    null

  • Sendredirect() from a servlet to a jsp page

    Hi all,
    From word document, I have some links like this: http://localhost:8080/Test/GetFileServlet?Name=Peter&Age=12
    when I click on the link, the GetFileServlet will check for user authentication.
    If i haven't logged in yet, servlet will kick me to Login.jsp (jsf) to login. I use a servlet filter to filter users.
    Once logged in, the page backing bean of login.jsp (Login.java) will send me to output.jsp which is only accessable to authenitcated users.
    That works great......
    Here is the problem when I click on the same link again.. With that I'm expecting the Servlet to kick me straight to output.jsp of JSF
    However, it keeps kicking me back to the login.jsp instead of output.jsp...
    Here is my sendredirect code in servlet
    resp.sendRedirect("http://10.80.54.240:8080/Test/faces/Local/output.jsp?Name=Peter&Age=12);

    iT'S OK..i fixed it using dispatcher

  • Send some atributes from a Servlet to a JSP program

    Hi all,
              I am quite new to JSP programming and am facing a problem. I have a
              Servlet code which is supposed to send some attributes to a JSP, which
              will display the attribute that has been passed through the Servlet.
              the Servlet code to do so is,
              request.setAttribute("emailtxt","emailNewTxt");
              RequestDispatcher rd=request.getRequestDispatche("/emailChangeSuc.jsp");
              rd.forward(request,response);
              on the JSP side, I am reciving this attribute in the following way,
              <body>
              <%@content_type="text/html"%>
              <%! String emailTxt=HttpSession.getAttribute("emailNewTxt");%>
              and am displaying the value in this way
              <b><%=emailTxt%>
              but I am getting an error
              "non-static method getAttribute(java.lang.String) cannot be referenced
              from a static context
              probably occurred due to an error in /emailChangeSuc.jsp line 9:
              <%! String emailTxt=HttpSession.getAttribute("emailNewTxt");%>"
              Please help me solve this problem.
              Thanks in anticipation,
              Rajiv.
              

    "Rajiv" == Rajiv <[email protected]> writes:
                        Rajiv> Hi all,
              Rajiv> I am quite new to JSP programming and am facing a problem. I have a
              Rajiv> Servlet code which is supposed to send some attributes to a JSP, which
              Rajiv> will display the attribute that has been passed through the Servlet.
              Rajiv> the Servlet code to do so is,
              Rajiv> {
              Rajiv> request.setAttribute("emailtxt","emailNewTxt");
              Rajiv> RequestDispatcher rd=request.getRequestDispatche("/emailChangeSuc.jsp");
              Rajiv> rd.forward(request,response);
              Rajiv> }
              Rajiv> on the JSP side, I am reciving this attribute in the following way,
              Rajiv> <body>
              Rajiv> <%@content_type="text/html"%>
              Rajiv> <%! String emailTxt=HttpSession.getAttribute("emailNewTxt");%>
              Rajiv> and am displaying the value in this way
              Rajiv> <b><%=emailTxt%>
              Rajiv> but I am getting an error
              Rajiv> "non-static method getAttribute(java.lang.String) cannot be referenced
              Rajiv> from a static context
              Rajiv> probably occurred due to an error in /emailChangeSuc.jsp line 9:
              Rajiv> <%! String emailTxt=HttpSession.getAttribute("emailNewTxt");%>"
              First of all, you put the attribute into the request, but you're trying to read
              it from the session. Change it to "request.getAttribute(...".
              Second, your compile error is stating that the "getAttribute()" method of
              HttpSession is not a static method. If you really needed to reference the
              session, it would just be "session". Changing to "request" as in the first
              point, will avoid this problem.
              Third, remove the "!" from the scriptlet which declares and sets the "emailTxt"
              variable. That makes it declare an instance variable instead of a local
              variable. That will cause numerous problems with this.
              ===================================================================
              David M. Karr ; Java/J2EE/XML/Unix/C++
              [email protected] ; SCJP; SCWCD
              

  • Execute a command from servlet

    Hello,
    How can I execute this command from a servlet ?
    example: I want execute "java -cp /root/:/root/log/api/:/root/log/apps/ Transmitter" when I lunch servlet1.java
    so which class in JAVA can do this ?
    Thanks ?

    why u want to run another program? Usually you call the methods within the second program.
    Is it possible to invoke another program in the server using a servlet? If so it could even mess up the whole server. I am not sure.

  • How to get the value from a servlet?

    Hello guys:
    how can i get the value from a servlet on my jsp page,for example return a boolean variable from a servlet
    which API to use?
    thanks

    Hi
    There is no specific API for this, call the method of the servlet which returns the required value in your JSP page.
    Thanks
    Swaraj

  • How to forward from a servlet to a (secured) jsp

    hi all
    actually i am trying to forward a request from a servlet to a jsp which is located in the WEB-INF-directory of the web-app...
    as i read in the docs the path in the getRequestDispatcher-method must start with a "/" so i tried to get a requestDispatcher-object from this path:
    /WEB-INF/secureJSP/abc.jsp...
    but all i get is a FileNotFoundException: no ressource "..." in the servlet context root "..."
    if i put the jsp in the web-app-root (like /abc.jsp) i am able to get a requestDispatcher-object without troubles...
    whats wrong? any ideas?
    tia
    sandro

    Hi
    Let me clarify this for you, Firstly as I said the WEB-INF directory is not accessible to the browser i.e a user couldn't possibly type in http://server-name:port-number/myapp/WEB-INF/test.jsp - This wouldn't work. But what you can do is forward a request to the jsp through a servlet using the RequestDispatcher.
    The RequestDispatcher object can be obtained in two ways. One is from the servletContext and the other is from the request. If it is obtained from the servletContext then the path is interpreted relative to the root of the web application. If it is got from the request without the "/" then the path is interpreted relative to the current request servicing resource.
    In your case get the RequestDispatcher from the ServletContext and provide the path as you have provided - assuming that WEB-INF directory is just below your myapp directory.
    Keep me posted on your progress & sorry for the confusion.
    Good Luck!
    Eshwar Rao
    Developer Technical Support
    Sun microsystems inc
    http://www.sun.com/developers/support

  • How do you launch browser from a servlet

    I have an interesting issue here. I send data to a servlet and the servlet recieves and processes the data (confirmed through breakpoints) but I want to display the data in a JSP or directly thru the servlet using html tags.
    However I can forward or redirect the data from the servlet to my jsp code but this still doesn't launch a browser.
    A little more detail... I am not sending information from a JSP to the servlet. The servlet is listening on a port for input, so the servlet is being invoked directly when the data comes in. In the current state my servlet sends the results in a session object to a JSP which gets the results but can't display them since it doesn't launch browser.
    Does anybody know how to display my calculated results from the servlet in a browser?

    Ok let me try to be more specific. I have an application that sends data to the servlet over a socket connection. The servlet gets this data and multiplies it by a factor.
    When I put break points in, I see that the servlet gets this data.
    Now I am trying to display the data in a browser.
    Upon entry to doGet the servlet checks if the String variable that gets the parameter is not null. If it is not null then it forwards to a JSP.
    But I tried a scenario where I have a browser open that has the localhost address of the servlet and then I run the program which is outside the war file that contains the servlet to send data to the servlet, but when the servlet gets the data, it does the forward to the JSP but the page is not displayed. However I see the process move to the JSP thru the break points I put in.
    I know its kind of a weird scenario but I suspect that since the program calls the servlet and it gets the data, it must need to launch a new browser in order to be able to display the JSP it forwarded to.
    I could be wrong but so far I have exhausted all possible ideas in my head for now so if you understand what I am saying perhaps you can tell me if you know a better way to do this...
    Thanks

  • Passing parameter to a jsp from a servlet

    Hi,
    I need to pass a parameter from a servlet to a jsp without using the session object. Is it possible? I've been looking for a method like response.setParameter but it doesn't exist.
    Please help !!!

    Actually, there is no setParameter method in the ServletRequetsObject. Still, you can create one. This can be usefull when you have a jsp that get its parameters from either a direct html form posting or a forward from a servlet. This can be achieved using wrappers, instead of the real request object.
    It's not really tricky, it's only a little "underknown" feature.
    Here is a sample code when you can fake the settings of requets parameters :
    public class MyRequest extends HttpServletRequestWrapper {
       private HashMap fakedParameters;
       public MyRequest(HttpServletRequest nested) {
          super(this);
          fakedParameters=new HashMap();
        public void setParameter(String key,String value) {
            fakedParameters.put(key,value);
        public String getParameter(String name) {
           String res=fakedParameter.get(name):
           if (res==null)
               res=super.getParameter(name);
           return res;
    }NB: this is a sample, you may also override other method (such as getParameterNames) for a full featuerd wrapped request.
    Now, you can use your wrapped request :
    MyRequest req2=new MyRequest(request);
    RequestDispatcher dispatcher=request.getRequestDispatcher("/somePage.jsp");
    req2.setParameter("name","yourName");
    dispatcher.formard(req2,response);Hope it helps.

Maybe you are looking for

  • IPhoto 06 corruption

    I have just upgraded from iPhoto '05 to iPhoto '06. Prior to this I duplicated the working iPhoto '05 "iPhoto Library" so I have a viable backup / back out plan. Launching iPhoto '06 for the first time asks about updating the iPhoto Library. I accept

  • E-mail Template and Smartforms

    Hi, Can any one tell me how to create E-mail templates and Smart forms and how to configure them in IC WEB to trigger automatically.  Thanks in advance.  Enough points will be given for right answer. Thanks, Rik

  • Where to store Reports on Unix

    Hello, where to store Reports in HPUX system, means in which directory.... regards, JAK

  • XMLSocket CLOSE and IO_ERROR event seem slow

    We are using an XMLSocket and are listening for the CLOSE and IO_ERROR events. When the server closes the connection or we disconnect our internet cable it seems to take about 15 to 20 seconds for the event to be caught. In the past it seems like it

  • Spotlight no longer indexes remote server

    I have a small network of Mac, one of which acts as our "server" simply by sharing a raid disk set up. Spotlight on the other Macs has always been able to index the contents of this "server". Because the results from searches have lately been eratic,