Setenv from a servlet (all on solaris)

Hi,
I have read the previous discussions about setting system env variables from java programs, but my problem is more specific:
The servlet can execute (through the Runtime class) the 'env' command, and return a list of its env, but when I try adding something to that env, by using the setenv command (just like from the command line), I get an IOException saying that 'setenv: not found'.
Does this have anything to do with the fact that it is being done through a servlet? There is no way I can do without setting that variable because it is needed by another command that my program also executes. I have not reached the point to check if setting the env variable through the servlet will be 'readable' by that command, but I am not at that point, yet.

You should be able to use the setenv command. perhaps the command is not in your path tho. Could that be the problem?

Similar Messages

  • Problem with Sessions, Servlets, Netscape and Solaris

    We are experiencing a problem that is confounding and frustrating us (I have
              a felling that it is something exremely minor that we are overlooking).
              Here goes:
              Context:
              The problem only occurs when using a netscape browser against weblogic
              4.51running on our Solaris 7 box (Everything works fine through IE, and
              through both browsers against our development machines which are on NT)
              Problem:
              We have a bunch of JSP pages and servlets that are used togehter throughout
              our site. They both manage session information for the user. What is
              happening is that there is no problem maintaining session information among
              all the JSP pages, but when we hit a servlet that we use to stream graphs
              back to the browser, it gets the session but it has no contents all of a
              sudden. What seems to be even more strange is that the session is not
              tagged as new (by checking isNew()), it is just empty of the contents that
              were placed it by the JSP pages. Again, this is only occurring from
              Netscape browsers against our Solaris server.
              If anyone can provide any help it would be greatly appreciated. I can
              provide more details if need be.
              Jeremy
              

    There is a property in the weblogic.properties file that lets you set
              the cookie name. If this isn't set, the port will be appended as part of
              the name. I've had a similar problem switching between http and https
              and losing sessions.
              Carles
              Jeremy wrote:
              >
              > in the link tothe servlet the URL had a :80 in it. This was because the url
              > was generated by a JSP page so that when it was moved from server to server
              > and port to port the code wouldn't have to be changed. Unfortuneately,
              > Netscape sucks and takes this to mean that x.x.x.x and x.x.x.x:80 are
              > different and won't acknowledge the cookie from the JSP pages (x.x.x.x) to
              > the servlet (x.x.x.x:80). Thanks fpr your help.
              >
              > Jeremy <[email protected]> wrote in message
              > news:[email protected]...
              > > my mistake, it appears to always happen on port 80 regardless of the
              > server
              > > it is on.
              > >
              > > Jeff Martin <[email protected]> wrote in message
              > > news:[email protected]...
              > > > It really sounds like your servlet is making a new session, even though
              > > > isNew() doesn't say so. What you might try to do is use session.getId()
              > > > to print out the session ID from your jsp pages as well as your servlets
              > > > to determine if it really is a new session.
              > > >
              > > > Do your servlets and JSPs both use the same scheme (http or https) or
              > > > cookie.setSecure()? Do your cookies use domains or paths in either
              > > > servlets or jsps (cookies can be restricted to certain subdirectories
              > > > which might be different between jsps and servlets)? Are you testing
              > > > through a proxy or firewall, or does either browser have different proxy
              > > > settings than the others?
              > > >
              > > > Jeff
              > > >
              > > > Jeremy wrote:
              > > > >
              > > > > We are experiencing a problem that is confounding and frustrating us
              > (I
              > > have
              > > > > a felling that it is something exremely minor that we are
              > overlooking).
              > > > > Here goes:
              > > > >
              > > > > Context:
              > > > > The problem only occurs when using a netscape browser against weblogic
              > > > > 4.51running on our Solaris 7 box (Everything works fine through IE,
              > and
              > > > > through both browsers against our development machines which are on
              > NT)
              > > > >
              > > > > Problem:
              > > > > We have a bunch of JSP pages and servlets that are used togehter
              > > throughout
              > > > > our site. They both manage session information for the user. What is
              > > > > happening is that there is no problem maintaining session information
              > > among
              > > > > all the JSP pages, but when we hit a servlet that we use to stream
              > > graphs
              > > > > back to the browser, it gets the session but it has no contents all of
              > a
              > > > > sudden. What seems to be even more strange is that the session is not
              > > > > tagged as new (by checking isNew()), it is just empty of the contents
              > > that
              > > > > were placed it by the JSP pages. Again, this is only occurring from
              > > > > Netscape browsers against our Solaris server.
              > > > >
              > > > > If anyone can provide any help it would be greatly appreciated. I can
              > > > > provide more details if need be.
              > > > >
              > > > > Jeremy
              > >
              > >
              

  • Error while opening a Office 2007 Excel (.xlsx) from a Servlet

    Hi All,
    Actually i am trying to open an excel file from a servlet. It works fine when the file format is .xls. But if it is .xlsx it gives the below error.
    "The file you are trying to open .xlsx is in a different format than specified by the file extension. verify the file is not corrupted and is from trusted source before opening the file. Do you want to open the file now?"
    There is a link in the application. When we click the link it calls the servlet. The servlet calls the DAO. The DAO queries the DB and the whole output is stuffed into a StringBuffer and the StringBuffer is written to the ServletOutputStream. I have used
    File newFile = new File("ABC.xslx");
    response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
    I have also included the below in the web.xml file.
    <mime-mapping>
    <extension>xlsx</extension>
    <mime-type>application/vnd.openxmlformats-officedocument.spreadsheetml.sheet</mime-type></mime-mapping>
    Kindly help me out.
    Thanks.

    Hi,
    I tried to create an excel through POI 3.5 using a simple java program. I am getting the same error when i try to open it.Below is my code. Kindly let me know the problem.
    I am getting the error ""The file you are trying to open .xlsx is in a different format than specified by the file extension. verify the file is not corrupted and is from trusted source before opening the file. Do you want to open the file now?" when opening the .xlsx file.
    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import java.io.File;
    import java.io.IOException;
    import java.util.ArrayList;
    import org.apache.poi.hssf.usermodel.HSSFRow;
    import org.apache.poi.hssf.usermodel.HSSFSheet;
    import org.apache.poi.hssf.usermodel.HSSFWorkbook;
    public class test {
    public static void main(String args[]) throws IOException{
    //ExportLobBean exportLobsForm = null;
    HSSFWorkbook wb = new HSSFWorkbook();
    HSSFSheet sheet = wb.createSheet();
    //ArrayList lobList = ExportLobBO.getArrayList();
    //int length = lobList.size();
    int rowCount=0;
    int count=0;
    HSSFRow headerRow = sheet.createRow((short) 0);
    HSSFRow dataRow = null;
    //Creating Column Names
    headerRow.createCell((short)0).setCellValue("LOB-ID");
    headerRow.createCell((short)1).setCellValue("LOB-NAME");
    headerRow.createCell((short)2).setCellValue("WEIGHT");
    for(int i=0;i<5;i++){
    rowCount++;
    sheet.createRow((short)rowCount);
    //exportLobsForm = (ExportLobBean)lobList.get(count);
    headerRow.createCell((short)0).setCellValue(1);
    //LOGGER.info("Lob id "+exportLobsForm.getStrLobId());
    headerRow.createCell((short)1).setCellValue(2);
    //LOGGER.info("Lob name"+exportLobsForm.getStrLobName());
    headerRow.createCell((short)2).setCellValue(3);
    //LOGGER.info("Lob weight"+exportLobsForm.getStrLobWeight());
    count++;
    File f = new File("c:\\test.xlsx");
    FileOutputStream fos = new FileOutputStream(f);
    wb.write(fos);
    }

  • Calling a WS from a servlet...EndpointPort does not contain operation meta.

    Hi all,
    I'm trying to call a service from a servlet but I get an error:
    Error: Endpoint {http://com.susan/SusanWS}SusanWebServiceEndpointPort does not contain operation meta data for: LoginWebService
    ...the WS is up and running (of this I'm sure...cause I also tested it with soapui...and it works..)
    The webservice is running on a local jboss (to which i can successfully connect, and see the wsdl...).
    the servlet is running on a local tomcat (which is also ok...).
    I'm trying to call the WS like this:
    Service service = new Service();
    Call call = (Call)service.createCall();
    call.setTargetEndpointAddress( new URL( wsEndpoint ) ); //http://localhost:8080/webservices/SusanWS (the same I used in soapui...so it should be right)
    call.setOperationName( "LoginWebService"); //name of the method i want to use...
    call.addParameter( "appCode", Constants.XSD_STRING, ParameterMode.IN );
    call.addParameter( "login", Constants.XSD_STRING, ParameterMode.IN );
    call.addParameter( "passwd", Constants.XSD_STRING, ParameterMode.IN );
    //            call.setReturnType( Constants.XSD_INT ); //left this out...should be the cause...
    Object retval = call.invoke( new String[] { appCode, login, passwd} ); //appCode,login,passwd contain the strings i want to  forward as input.if I try to run it I get(in the jboss log...):
    15:41:55,594 ERROR [SOAPFaultExceptionHelper] SOAP request exception
    javax.xml.rpc.soap.SOAPFaultException: Endpoint {http://com.susan/SusanWS}SusanWebServiceEndpointPort does not contain operation meta data for: LoginWebService
    at org.jboss.ws.server.ServiceEndpointInvoker.getDispatchDestination(ServiceEndpointInvoker.java:181)
    at org.jboss.ws.server.ServiceEndpointInvoker.invoke(ServiceEndpointInvoker.java:107)
    at org.jboss.ws.server.ServiceEndpoint.handleRequest(ServiceEndpoint.java:209)
    at org.jboss.ws.server.ServiceEndpointManager.processSOAPRequest(ServiceEndpointManager.java:355)
    at org.jboss.ws.server.StandardEndpointServlet.doPost(StandardEndpointServlet.java:115)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at org.jboss.ws.server.StandardEndpointServlet.service(StandardEndpointServlet.java:76)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
    at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
    at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:175)
    at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:74)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
    at org.jboss.web.tomcat.tc5.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:156)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
    at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
    at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
    at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
    at java.lang.Thread.run(Thread.java:595)
    don't know if it can help...the soapui request looks like this:
    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:typ="http://com.susan/SusanWS/types">
    <soapenv:Header/>
    <soapenv:Body>
    <typ:LoginWebService>
    <LoginInfo_1>
    <appCode>WEB_SERVICES</appCode>
    <login>root</login>
    <passwd>root</passwd>
    </LoginInfo_1>
    </typ:LoginWebService>
    </soapenv:Body>
    </soapenv:Envelope>
    anybody has an idea of what I'm doing wrong?
    Edited by: Turbo-555 on Mar 18, 2009 8:36 AM

    if I change the code with:
    //call.setOperationName( wsMethod );
    call.setOperationName( new QName("http://com.susan/SusanWS",wsMethod)); //http://com.susan/SusanWS is the targetnamespace...the error changes into:
    16:55:21,051 ERROR [SOAPFaultExceptionHelper] SOAP request exception
    javax.xml.rpc.JAXRPCException: Cannot find child element: {http://com.susan/SusanWS/types}LoginWebService
    at org.jboss.ws.binding.soap.SOAPBindingProvider.getParameterFromMessage(SOAPBindingProvider.java:799)
    at org.jboss.ws.binding.soap.SOAPBindingProvider.unbindRequestMessage(SOAPBindingProvider.java:282)
    at org.jboss.ws.server.ServiceEndpointInvoker.invoke(ServiceEndpointInvoker.java:112)
    at org.jboss.ws.server.ServiceEndpoint.handleRequest(ServiceEndpoint.java:209)
    at org.jboss.ws.server.ServiceEndpointManager.processSOAPRequest(ServiceEndpointManager.java:355)
    at org.jboss.ws.server.StandardEndpointServlet.doPost(StandardEndpointServlet.java:115)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at org.jboss.ws.server.StandardEndpointServlet.service(StandardEndpointServlet.java:76)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
    at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
    at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:175)
    at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:74)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
    at org.jboss.web.tomcat.tc5.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:156)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
    at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
    at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
    at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
    at java.lang.Thread.run(Thread.java:595)

  • Invoking BPEL process from Java servlet with org.w3c.dom.Element as payload

    Hello,
    I'm trying to initiate a BPEL process from my servlet running under Tomcat. When I create the NormalizedMessage passing the XML as a String everything works fine. But if I use an org.w3c.domElement the BPEL server doesn't react at all (even on DEBUG log level there are no outputs).
    This works:
    NormalizedMessage message = new NormalizedMessage();
    message.addPart("payload", "<foo></foo>");
    This doesn't work:
    org.w3c.dom.Element elem;
    oracle.xml.parser.v2.XMLDocument xmlDocument;
    NormalizedMessage message = new NormalizedMessage();
    Element elem = xmlDocument.createElement("foo");
    message.addPart("payload", elem);
    Is there a known problem with payloads using Element or did I get something completely wrong? Thanks in advance,
    Hans.

    Hello,
    I'm trying to initiate a BPEL process from my servlet running under Tomcat. When I create the NormalizedMessage passing the XML as a String everything works fine. But if I use an org.w3c.domElement the BPEL server doesn't react at all (even on DEBUG log level there are no outputs).
    This works:
    NormalizedMessage message = new NormalizedMessage();
    message.addPart("payload", "<foo></foo>");
    This doesn't work:
    org.w3c.dom.Element elem;
    oracle.xml.parser.v2.XMLDocument xmlDocument;
    NormalizedMessage message = new NormalizedMessage();
    Element elem = xmlDocument.createElement("foo");
    message.addPart("payload", elem);
    Is there a known problem with payloads using Element or did I get something completely wrong? Thanks in advance,
    Hans.

  • I want to send a response from the servlet and then call another servlet.

    Hi,
    I want to send a response from the servlet and then call another servlet. can this happen. Here is my scenario.
    1. Capture all the information from a form including an Email address and submit it to a servlet.
    2. Now send a message to the browser that the request will be processed and mailed.
    3. Now execute the request and give a mail to the mentioned Email.
    Can this be done in any way even by calling another servlet from within a servlet or any other way.
    Can any one Please help me out.
    Thanks,
    Ramesh

    Maybe that will help you (This is registration sample):
    1.You have Registration.html;
    2.You have Registration servlet;
    3.You have CheckUser servlet;
    4.And last you have Dispatcher between all.
    See the code:
    Registration.html
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <HTML>
      <HEAD>
        <TITLE>Hello registration</TITLE>
      </HEAD>
      <BODY>
      <H1>Entry</H1>
    <FORM ACTION="helloservlet" METHOD="POST">
    <LEFT>
    User: <INPUT TYPE="TEXT" NAME="login" SIZE=10><BR>
    Password: <INPUT TYPE="PASSWORD" NAME="password" SIZE=10><BR>
    <P>
    <TABLE CELLSPACING=1>
    <TR>
    <TH><SMALL>
    <INPUT TYPE="SUBMIT" NAME="logon" VALUE="Entry">
    </SMALL>
    <TH><SMALL>
    <INPUT TYPE="SUBMIT" NAME="registration" VALUE="Registration">
    </SMALL>
    </TABLE>
    </LEFT>
    </FORM>
    <BR>
      </BODY>
    </HTML>
    Dispatcher.java
    package mybeans;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import javax.servlet.ServletException;
    import java.io.IOException;
    import javax.servlet.RequestDispatcher;
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    public class Dispatcher extends HttpServlet {
        protected void forward(String address, HttpServletRequest request,
                               HttpServletResponse response)
                               throws ServletException, IOException {
                                   RequestDispatcher dispatcher = getServletContext().
                                   getRequestDispatcher(address);
                                   dispatcher.forward(request, response);
    Registration.java
    package mybeans;
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    public class Registration extends Dispatcher {
        public String getServletInfo() {
            return "Registration servlet";
        public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            ServletContext ctx = getServletContext();
            if(request.getParameter("logon") != null) {          
                this.forward("/CheckUser", request, response);
            else if (request.getParameter("registration") != null)  {         
                this.forward("/registration.html", request, response);
    CheckUser.java
    package mybeans;
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.sql.*;
    public class CheckUser extends Dispatcher {
        Connection conn;
        Statement stat;
        ResultSet rs;
          String cur_UserName;
        public static String cur_UserSurname;;
        String cur_UserOtchestvo;
        public String getServletInfo() {
            return "Registration servlet";
        public void service(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
            try{
                ServletContext ctx = getServletContext();
                Class.forName("oracle.jdbc.driver.OracleDriver");
                conn = DriverManager.getConnection("jdbc:oracle:oci:@eugenz","SYSTEM", "manager");
                stat = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
               String queryDB = "SELECT ID, Login, Password FROM TLogon WHERE Login = ? AND Password = ?";
                PreparedStatement ps = conn.prepareStatement(queryDB); 
               User user = new User();
            user.setLogin(request.getParameter("login"));
            String cur_Login = user.getLogin();
            ps.setString(1, cur_Login);
            user.setPassword(request.getParameter("password"));
            String cur_Password = user.getPassword();
            ps.setString(2, cur_Password);
         Password = admin");
            rs = ps.executeQuery();
                 String sn = "Zatoka";
            String n = "Eugen";
            String queryPeople = "SELECT ID, Surname FROM People WHERE ID = ?";
           PreparedStatement psPeople = conn.prepareStatement(queryPeople);
                      if(rs.next()) {
                int logonID = rs.getInt("ID");
                psPeople.setInt(1, logonID);
                rs = psPeople.executeQuery();
                rs.next();
                       user.setSurname(rs.getString("Surname"));
              FROM TLogon, People WHERE TLogon.ID = People.ID";
                       ctx.setAttribute("user", user);
                this.forward("/successLogin.jsp", request, response);
            this.forward("/registration.html", request, response);
            catch(Exception exception) {
    }CheckUser.java maybe incorrect, but it's not serious, because see the principe (conception).
    Main is Dispatcher.java. This class is dispatcher between all servlets.

  • Forms applet does not load when request forwarded from custom servlet

    I have an existing forms app that I wish to call from a newly-developed servlet. The servlet determines which form to call and then forwards the request to the forms servlet using RequestDispatcher.forward().
    The request is forwarded correctly but when it is done all I see is a blank browser (IE7) window. When I View Source I see all the correct HTML code (from basejpi.htm) but it seems my browser does not attempt to load the forms applet. No messages are displayed in the Java Console. This is the same HTML that comes back if I run the forms app directly, e.g. click a link that goes straight to the forms servlet URL, only in that case the forms app starts up fine.
    Anyone know why this does not work?

    Figured out what is going on:
    In basejpi.htm there is "<SCRIPT LANGUAGE=JavaScript SRC=java/forms_ie.js>" that creates an OBJECT tag to load the forms applet. I believe since the context of my custom servlet is different than that of the forms servlet, forms_ie.js is not found when the request is forwarded from my servlet.
    One question answered raises another. There is also an OBJECT tag inside a NOSCRIPT tag for machines where scripting has been disabled:
    <!-- Forms applet definition (start) -->
    <NOSCRIPT>
    <OBJECT name=FormsApplet
    type="application/x-java-applet"
    ...>
    </NOSCRIPT>
    <SCRIPT LANGUAGE="JavaScript" SRC="java/forms_ie.js"></SCRIPT>
    My thinking is to remove the NOSCRIPT tag, and also the SCRIPT tag mentioned above, so all machines will simply see the OBJECT tag, like so:
    <!-- Forms applet definition (start) -->
    <OBJECT name=FormsApplet
    type="application/x-java-applet"
    ...>
    This makes me wonder why the SCRIPT option is there to begin with. Anyone see a downside to this approach?
    Kevin

  • How to write from a servlet to it's war file?

    We need to be able to write a file from a servlet into the document root
              area to it can be accessed by a browser. Before we used war files, we
              would simply figure out the real document root directory and write the
              file somewhere under it. How would I do this when my application is
              packaged as a war? I don't see a way to write to a "xxx.war" file and
              if we run from an exploded war, how do I determine the location of the
              document root at runtime from the servlet? I don't want to have to hard
              code the path or make each installation specifiy it in a properties
              file. It seems there should be a better way to handle this. Any ideas?
              

    Thanks for your help. Not to beat this to death but say I want a response that
              includes a bunch of HTML generated by a servlet or JSP and in the middle I want
              a dynamically created image. So basically I want an <image> tag in the middle
              of the html returned. Could I dynamically generate the image and add it to the
              response in the middle of the servlet/JSP processing? I thought the only option
              would be to return an html page the referred to an image via an <image> tag.
              What do you think?
              Kirk
              Cameron Purdy wrote:
              > Hi Kirk,
              >
              > Yes, you can accomplish all of those things without writing files out.
              > Writing files will severely degrade performance in many cases, and will lead
              > to certain classes of bugs such as those caused by multiple browsers within
              > the same process or rampant use of "back" lists. (That's a long-winded way
              > of saying persistent state on the server that reflects a client's transient
              > state has a way of being wrong, sooner or later.)
              >
              > All you have to do is return a URL that includes the necessary information
              > to get the picture. You do that now by creating a random thingamabob name:
              >
              > http://www.mysite.com/myapp/thisisarandomname12345.jpg
              >
              > Instead of random, try:
              >
              > http://www.mysite.com/myapp/thisisthepictureforemployee-17.jpg
              >
              > The issues are the same (someone trying to guess URLs) but you do have the
              > problem that the URLs are easier to guess because they follow a pattern.
              > You should secure-check each request anyway. (Lots of tricks for making
              > that very efficient, but that is a book in itself.)
              >
              > So what serves up the .jpg? A Servlet!!! It gets the request, builds (or
              > reads from db or whatever) the .jpg image and streams it out. Now you get
              > 3-4 times the performance and a much more orderly arrangement of URLs etc.
              > that can now be "saved" and "bookmarked" etc. Also no congested temp dirs
              > etc.
              >
              > Peace,
              >
              > --
              > Cameron Purdy
              > Tangosol, Inc.
              > http://www.tangosol.com
              > Tangosol Server: Enabling enterprise application customization
              >
              > "Kirk Everett" <[email protected]> wrote in message
              > news:[email protected]...
              > > What I want to do is one one servlet request generate an image file in the
              > doc
              > > root and then return a page back to the browser that contains an image tag
              > > referring to the generated image file. I also want to be able to generate
              > a file
              > > of data based on a user's posted selections and then present them with a
              > link to
              > > download the file. If I don't write these to disk in the docroot how
              > would I
              > > give the user a link to them? Is there a better way? Thanks for your
              > help.
              > >
              > > Kirk
              > >
              > > Cameron Purdy wrote:
              > >
              > > > Yes, if you have to write a file (either because you expect it to be
              > used
              > > > many times or you wish to assemble a huge (>1mb) response without using
              > > > memory), then do so to a temp or working dir. There is no reason to use
              > the
              > > > doc root at all for that, other than to use FileServlet, which is eaily
              > > > replicated for your own specific purposes. For the most part, there is
              > no
              > > > reason to write the file, since you can write the response back to the
              > > > browser just as easily as to a file.
              > > >
              > > > Peace,
              > > >
              > > > --
              > > > Cameron Purdy
              > > > Tangosol, Inc.
              > > > http://www.tangosol.com
              > > > +1.617.623.5782
              > > > WebLogic Consulting Available
              > > >
              > > > "Kirk Everett" <[email protected]> wrote in message
              > > > news:[email protected]...
              > > > > I agree that in general this should be avoided but we have two cases
              > where
              > > > we
              > > > > need to write a file to the
              > > > > the document root. The first is we allow the user to generate a file
              > and
              > > > > download it to thier machine. So in
              > > > > one servlet the user selects the data and submits the form. The
              > servlet
              > > > then
              > > > > writes a file to the docroot and
              > > > > the user is then presented a link where they can download the file.
              > The
              > > > second
              > > > > is when we want to generate
              > > > > a chart image in a gif. The servlet writes the image to the docroot
              > and
              > > > another
              > > > > JSP refers to the image in an
              > > > > image tag. In both cases we are using mangled names and we clean up
              > the
              > > > files.
              > > > > Do you have a better solution?
              > > > > Thanks for your help.
              > > > >
              > > > > Cameron Purdy wrote:
              > > > >
              > > > > > Writing to a deployed application is generally a thing to be
              > avoided.
              > > > Among
              > > > > > other things, it is a potential security issue. Apps should be able
              > to
              > > > be
              > > > > > locked down (no OS write access except non-exec temp space). I
              > suggest
              > > > not
              > > > > > doing writes if at all avoidable. What are you trying to
              > accomplish?
              > > > > > Perhaps stream back a big file?
              > > > > >
              > > > > > Peace,
              > > > > >
              > > > > > --
              > > > > > Cameron Purdy
              > > > > > Tangosol, Inc.
              > > > > > http://www.tangosol.com
              > > > > > +1.617.623.5782
              > > > > > WebLogic Consulting Available
              > > > > >
              > > > > > "Kirk Everett" <[email protected]> wrote in message
              > > > > > news:[email protected]...
              > > > > > > We need to be able to write a file from a servlet into the
              > document
              > > > root
              > > > > > > area to it can be accessed by a browser. Before we used war files,
              > we
              > > > > > > would simply figure out the real document root directory and write
              > the
              > > > > > > file somewhere under it. How would I do this when my application
              > is
              > > > > > > packaged as a war? I don't see a way to write to a "xxx.war" file
              > and
              > > > > > > if we run from an exploded war, how do I determine the location of
              > the
              > > > > > > document root at runtime from the servlet? I don't want to have
              > to
              > > > hard
              > > > > > > code the path or make each installation specifiy it in a
              > properties
              > > > > > > file. It seems there should be a better way to handle this. Any
              > > > ideas?
              > > > > > >
              > > > >
              > >
              

  • Problem in retriving the realpath from the servlet

    Hai All,
    I am facing problem in retriving the realpath from the servlet.
    I am using the following code in order to retrieve the path.
    String prefix = getServletContext().getRealPath("/WEB-INF/classes");
    The value returned from above code is null.
    I am using Weblogic 8.1 server, and deploying my servlet as WAR file inside
    the weblogic server.
    Is this the problem with the weblogic server or with the code. Is there any way to over come this.
    I need the path as i am implementing Log4j for the servlet and i have to pass the
    configuration file in one of the function "PropertyConfigurator.configure(file);"
    where the file should include complete path.
    My configuration file is in WEB-INF/Classes directory.
    Any help is appreciated.
    Thanks in advance
    Pooja.

    String realPath = request.getRealPath(request.getContextPath());
    That should return the path up to where you have your servlet context.

  • Accesing same object from different servlets

    Hello all!
    I am developing a web control project. I am using a simulator of a factory (with java). The engineers are supposed to be able to change some variables from the web.
    I am using servlets to change this variables. My problem is that, to be able to change variables, I need to create an instance of this FactorySimulator object.
    If each servlet ( there are many servlets) calls an instance, they will be updating different FactorySimulator objects.
    How can I make reference, or have acces to the SAME object, from any servlet?
    Thanks! I hope my question is clear =)

    package com.yourcompany.somepackage;
    public class TheFactory
        private static FactorySimulator factory = new FactorySimulator();
        private TheFactory() {} // Static methods only, do not instantiate TheFactory
        public FactorySimulator instance()
            return factory;
    }From each of your servlets you can call TheFactory.instance().doWhataver(). Methods in FactorySimulator need to be suitably synchronized of course.

  • Accessing String assigned in a JSP from a Servlet?

    Hello all, I was wondering if there is a way to access a String object that was assigned by an HttpSession object in a JSP from a Servlet. What happens is, in my application a user logs in, an HttpSession object is instantiated and all of the user credentials are assigned within a JSP like:
    HttpSession httpSession = request.getSession( false );
    String userName = httpSession.getAttribute("userName);
    ...{code}
    Next, I have a Servlet (which is really just a Proxy to a different server), that I need to log some information with, namely the userName String. Is there a way I can access that String without instantiating another HttpSession object? Because when the timeout occurs (or when the user clears his cache I have found), the HttpSession becomes invalidated (even if I use  +HttpSession#getSession( true )+) and the +HttpSession#getAttribute+ call fails (userName is just null). So is this possible to do?
    Thanks in advance!                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    dnbphysicist wrote:
    I understand you cannot recover attributes from a dead session, this is why I wanted to be able to access a variable that is pulled from the Session immediately after login so I can still get to it even once the session is dead.
    Normally a session doesn't go dead after login.
    I imagine that by using application scope the app would confuse the userName with other users that are logged in?Certainly. It was just an example. But your data clearly belongs in the session, so just keep it in the session. If the session get invalidated while it should not get invalidated, then your problem truly lies somewhere else.
    I am definitely not arguing you latter point either :) A lot of this code I inherited unfortunately from previous developers and we are in desperate need of a redesign.I wish you much luck with that.

  • 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.~

  • Different ways to invoke a servlet from another servlets?

    Hello,
    I am a bit confused today. I was thinking about all the ways by which I can invoke a servlet from another servlets. I know it can be done by creating an instance of the 2nd servlet in the 1st one. Is there any other way? such as say.... RequestDispatcher perhaps?
    Here is an example to illustrate my point. I have a login.jsp which submits to login.do. login.do search through database and first authenticate email and then the corresponding password. Now its time for displayGame.do. So here how do i do? if it was a displayGame.jsp then i could have used Redirection or Forward but when it is servlets? Can I still go for Redirection or Forward??
    Thank you for reading this confused post. :-)

    if it was a displayGame.jsp then i could have used Redirection or Forward but when it is servlets?Question: do you know what a JSP becomes when you first run it?
    Answer: a servlet.
    So yes, you can use a RequestDispatcher to forward/redirect to a servlet OR a JSP, whatever you like.

  • Can I call a "function" from a servlet?

    A few of my servlets need to perform about the same computations (have large sections of identical code).
    It would save some disk space to be able to call a procedure from different servlets.
    Can this be done? How?
    Thank you all.

    A few of my servlets need to perform about the same
    computations (have large sections of identical code).
    It would save some disk space to be able to call a
    procedure from different servlets.
    Can this be done? How?This wouldn't be the way to do it.
    Since Java is an object oriented programming language, you should use it's concepts to implement a 'basic' class and than extend it. This means: Create a class that contains the basic procedures (you will never create an instance of this class) and then create all the serlvet classes by extending the 'mother' class. Like this you have the common code once in the 'mother' class and the specific code in the specific servlets.

  • Obtaining a Subjects username and password from a servlet

    Ok probably an easy one for people out there. I don't even know if it is
    possible.
    I have a servlet that has BASIC authentication going on (lets say it's using
    WebLogic 7.0 default security realm). From the servlet I need to explicitly
    obtain the user's username AND password. I have no problem retrieving the
    principal it's the password I can't get a hold of. I've tried all sorts of
    things like:
    javax.security.auth.Subject subject =
    weblogic.security.Security.getCurrentSubject(); and then trying to get the
    private credentials. No luck though.
    Any ideas? Is it possible?
    Mich

    Thanks for the response Neil.
    I need the password because my servlet is accessing a secure Web service.
    When connecting to the Web service I need to provide the username and
    password of the user (these are passed in String format) and I don't want to
    have the user provide username and password again when accessing the
    external Web service. So really I need to access the WLS security realm
    (where my servlet is executing) to obtain the current user's username and
    password. Will the default credential mapper in WLS give me the username
    and password in text format...from the limited documentation I have read it
    doesn't appear to. Is this correct?
    Mich
    "Neil Smithline" <[email protected]> wrote in message
    news:[email protected]..
    The password is not stored in the Subject. We do this to reduce the
    risk of the password being snooped from WLS's memory. If you wish you
    could write a LoginModule that puts the password in the private
    credentials and then creates an authentication provider that uses that
    LoginModule and make it part of the current realm.
    In general there is no way to get the password from within WLS. The
    passwords are stored in a salted one-way hashed format that is not
    reverse decryptable except via exhaustive search.
    Why do you need the password? If it is for a remote access can you use
    the credential mapper?
    - Neil
    Michel Crichton wrote:
    Ok probably an easy one for people out there. I don't even know if it
    is
    possible.
    I have a servlet that has BASIC authentication going on (lets say it'susing
    WebLogic 7.0 default security realm). From the servlet I need toexplicitly
    obtain the user's username AND password. I have no problem retrievingthe
    principal it's the password I can't get a hold of. I've tried all sortsof
    things like:
    javax.security.auth.Subject subject =
    weblogic.security.Security.getCurrentSubject(); and then trying to getthe
    private credentials. No luck though.
    Any ideas? Is it possible?
    Mich

Maybe you are looking for