How to get CATALINA_HOME in a servlet?
hello
I want to dynamically make some html files available to users, so I think I should first get the value of CATALINA_HOME, then copy these files to proper directories. How can I get this environment variable then?
Thanks for any reply!
Properties props = System.getProperties();
String cat = (String)props.get("catalina.home");
Similar Messages
-
How to get javabean data in Servlets.( JavaBean -- Servlet(Controller)
how to get javabean data in Servlets.
1) I am using name ,password in Jsp(View )
2) when I submit this Bean will be called and Setter methods will be called .
3) In ServletController (controller) I want to get data of javabean.
In this I have to do validation of user.
I want to pass the javabean obj as like -->
request.getAttribute("beanObj");
My intention is to get all the poperties in javabean by passing bean id
or beanobj ,
Is there any way to get all the data using bean id or beanObj.
Plz Reply,Now in the Servlet we can get the same bean by this code:
PageContext pageContext = JspFactoryImpl.getDefaultFactory().getPageContext(this, request, response, null, true, 8192, true);
UserBean userbean = (UserBean)pageContext.getAttribute("userbean", PageContext.SESSION_SCOPE);
String userid = userbean.getUsername();
For this code to work it is needed to import 2 files:
import org.apache.jasper.runtime.JspFactoryImpl;
import javax.servlet.jsp.PageContext;
The JspFactoryImpl is in jasper-runtime.jar file provided in tomcat dir.It seems to me that you are exactly knowing what you are doing :-(
You can get a Bean stored in a Session by
request.getSession().getAttribute("userbean");
In the login.jsp page for example we have the code
<jsp:useBean id="userbean" scope="session"class="com.newproj.UserBean" />
<jsp:setProperty name="userbean" property="*" />the jsp:setProperty is not called when you click on the submit button
if fills the bean with the request values from the previous request.
andi -
How to get XML file using servlets that XI sent to my J2EE appl?
Hi All!
I have a scenario like XI sends xml file to j2ee application. In my J2EE application my servlet receives this xml. Will the xml file be in my HTTPServletRequest object? if so how to get that file from Request object.
Please help me its urgent, Any code help is highly appreciated.
My xml file will be like this:
<ns0:Http_Message_Type_Demo
xmlns:ns0="http://abcdemo.com">
<Name>ABC</Name>
<RollNo>123</RollNo>
<Address>a-4</Address>
</ns0:Http_Message_Type_Demo>
somebody should help me!please
ThanksHi,
You can use HTTPServletRequest object to get the XML payload.
BufferedReader reader = request.getReader(); //gets XML payload
String line = reader.readLine(); // to read the XML payload line by line
(request is the HTTPServletRequest object)
Regards,
Uma -
How to get the data in servlet if the request encryption type is multipart/
I am uploading files to the server.
at that time,before upload ,I need to validate the upload file names.
so,i am trying to get the value of those files names using
request.getParameter("jobsheet"); in servlet.
its giving null insted of file path.
how to retrieve the the values of parameters if the request is multipart/form-data.
any help please...I think that package works in struts framework right?
If wrong ,correct me.
actually I am following MVC pattern.not using struts.
If this works even in normal web application also.then ok.
But,Just I am looking how to get the values of jsp parameters
I have 5 elements in jsp .
below code:
<form name="FileUpload" action="./UploadServlet" method="post" enctype="multipart/form-data">
country <input type="text" name="country" value="">
year <input type="text" name="year" value="">
month <input type="text" name="month" value="">
File<input type="file" name="file1" value="">
<input type="submit">
</form>
I am trying to get the data in servlet like
String country=req.getParameter("country");
its getting null.
I don't know how to get the values if the enctype is "enctype="multipart/form-data"
If any one knows ,Please suggest me. -
Submit a PDF as a PDF to a servlet, and how to get my PDF from servlet
Hi all as the title above,
i have a button typeformat as PDF and sent to a URL( which is my servlet )
after this step how to get the PDF from my servlet.
the PDF has sent to my servlet and stop, so is there any way to get the PDF i sent ?
can someone help me?
thanksYou can use the following code:
byte[] content = getRequestBufferAsBytes(request);
...then do whatever you want
public static byte[] getRequestBufferAsBytes(HttpServletRequest request) throws IOException, ServletException
// get the RequestBuffer
ServletInputStream oInput = request.getInputStream();
long nContentLength = request.getContentLength();
String contentType = request.getContentType();
if (nContentLength <= 0)
return null;
byte[] cContent = new byte[(int)nContentLength];
// read the content in 512 bytes chunks
// a single read does not get all the characters
int nRead = 0;
int nToRead = (int)nContentLength;
int nBlkSize = 512;
byte[] cTemp = new byte[512];
do {
int n = 0;
int i = 0;
if (nToRead - nRead < 512)
nBlkSize = nToRead - nRead;
n = oInput.read( cTemp,0,nBlkSize);
for (i = 0; i < n; i++)
cContent[i+nRead] = cTemp[i];
nRead += i;
} while (nRead < nToRead);
//cContent[nRead] = (byte)'\0';
Long nBytesRead = new Long( nRead );
return cContent;
Jasmin -
How to get XML value using servlet?
how to get values from a XML file using servlet ? Thank you.
for example: how can I get the location value (aaa) from this XML file?
abc.xml:
<business>
<location>aaa</location>
</business>Try to use XML Parsers to do the job.
Use DOM or SAX Parsers that are freely available.
Some of the popular ones are xerces, DOM, SAX. -
Hi How to get XML file from servlet that XI sent to my J2EE appl?
Hi All!
I have a scenario like XI sends xml file to j2ee application. In my J2EE application my servlet receives this xml. Will the xml file be in my HTTPServletRequest object? if so how to get that file from Request object.
Please help me its urgent, Any code help is highly appreciated.
My xml file will be like this:
<ns0:Http_Message_Type_Demo
xmlns:ns0="http://abcdemo.com">
<Name>ABC</Name>
<RollNo>123</RollNo>
<Address>a-4</Address>
</ns0:Http_Message_Type_Demo>
somebody should help me!please
ThanksHi,
You can use HTTPServletRequest object to get the XML payload.
BufferedReader reader = request.getReader(); //gets XML payload
String line = reader.readLine(); // to read the XML payload line by line
(request is the HTTPServletRequest object)
Regards,
Uma -
How to get response from a servlet which depends on cookies?
guys,
i have a servlet which behaves differently based on the presence of a cookie or not. If cookie A is present in the machine it shows the the home page and if not it shows the login page.
now i want to get the home page HTML content from a program without using the browser. i am aware this can be done by using java.net.URL but how do i simulate the cookie given that i know that's the cookie name and value it expects?
Unfortunately i cannot paste the servlet code as it is a servlet of a product and i don't have the source code for it.
Thanks
SI believe you use URLConnection.setRequestProperty(), with the key being "Cookie".
-
How to get "/r/n" in servlet after decoding a escaped URL
I am creating a servlet request in Javascript and need to send "/r/n" as value for one request parameter.
So I am doing escape(myURL) in Javascript and sending it to servlet.
escape converts "/r/n" to "%0D%0A".
Now in servlet I am using URLDecoder.decode() with UTF-8 but this translates these chars to "ctrl M".
I am not sure which char encoding type I should use to get "/r/n" chars back in servlets or any other way to do this job.
Any pointers highly appericated.
TIA,SachinI'm also having a servlet with some funky UTF-8 characters being passed encoded, but this takes care of it in doGet/Post:
request.setCharacterEncoding("UTF-8");
then,
String param = request.getParameter("PARAM");
puts everything encoded into string as strings are all Unicode as well...
hope this helps -
Help: how to get text from IFRAME
<!-- The box where we type-->
<IFRAME class="mytext" width="100%" ID="mytext" height="200">
</IFRAME>
someone can tell me how i get text in my servlet from
<IFRAME>
thankx in advance...someone can tell me how i get text in my servlet from
<IFRAME>
thankx in advance...Hmm. I think you are mixing something up here. Why would you use an IFrame for entering text? IFrame is used for including content from different HTML-pages inside your page.
If you want to have a textbox for an user to enter text into and submit it to a server, you need a form and a textarea inside that. Like this:
<form action="myServlet" method="post">
<textarea name="myArea">
</textarea>
<input type="Submit" value="Ok">
</form>Change the action in the form to reflect the mapping to your servlet.
Then you can just do a String enteredText = request.getParameter( "myArea" ); inside your servlet.
If you insist that you need to use an IFrame, I guess the only way to do it would be to write a Javascript function, that copies the contents from the IFrame to a hidden field before the page is submitted to your servlet. In your servlet you would read the value from the hidden field.
.P. -
How to get an ArrayList Object in servlet from JSP?
How to get an ArrayList Object in servlet from JSP?
hi all
please give the solution for this without using session and application...
In test1.jsp file
i am setting values for my setter methods using <jsp:usebean> <jsp:setproperty> tags as shown below.
After that i am adding the usebean object to array list, then using request.setAttribute("arraylist object")
---------Code----------
<jsp:useBean id="payment" class="com.common.PaymentHandler" scope="request" />
<jsp:setProperty name="payment" property="strCreditCardNo" param="creditCardNumber" />
<%-- <jsp:setProperty name="payment" property="iCsc" param="securityCode" /> --%>
<jsp:setProperty name="payment" property="strDate" param="expirationDate" />
<jsp:setProperty name="payment" property="strCardType" param="creditCardType" />
<%--<jsp:setProperty name="payment" property="cDeactivate" param="deactivateBox" />
<jsp:setProperty name="payment" property="fAmount" param="depositAmt" />
<jsp:setProperty name="payment" property="fAmount" param="totalAmtDue" /> --%>
<jsp:useBean id="lis" class="java.util.ArrayList" scope="request">
<%
lis.add(payment);
%>
</jsp:useBean>
<%
request.setAttribute("lis1",lis);
%>
-----------Code in JSP-----------------
In testServlet.java
i tried to get the arraylist object in servlet using request.getAttribute
But I unable to get that arrayObject in servlet.....
So if any one help me out in this, it will be very helpfull to me..
Thanks in Advance
EdwardHi,
Im also facing the similar problen
pls anybody help..
thax in advance....
Litty -
How to get absolute in servlet
how to get absolute in servlet like c:\temp\apache group\tomcat4.1\test\abc.gif, thanks
do sthing like:
getServletContext().getRealPath("/abc.gif") in any servlet in 'test' to get the real path of abc.gif - The parameter should be relative to the current context -
How to get correctly any non english data e.g greek data in servlet??
Hello All,
I have one textbox on form from where user will enter greek data and when i get that field data in servlet using request.getParameter("name") ,then it shows wierd text in servlet ,it ditorts all the characters that user enterd on page,how can i get greek data in servlet wothout losing it????
Please help
Thanks.1.) Read [this excellent introduction into Unicode|http://www.joelonsoftware.com/articles/Unicode.html]. The subject is more complex than you think.
2.) Verify at each point in your program that your String contains the correct value. Note that using System.out.println() might not be helpful here, since the console might not be able to display those characters.
3.) When a String contains invalid characters, then the error already happened before! Don't try to fix it after the fact, look where the original byte[]->String transition is made and make sure that it is correct. -
How to get javax.servlet package
Hi guys
Does anybody know how to get javax.servlet package?
Thanks in advance.
Regards,
Mark.I just moved the servlet jar into java_home/jre/lib/ext and I made some progress. Instead I recieved this error
---------- Javac ----------
Note: C:\jdk1.3.1_04\bin\java\lang\ThreadGroup.java uses or overrides a deprecated API.
Note: Recompile with -deprecation for details.
Normal Termination
Output completed (17 sec consumed).
DOes anyone have an idaea of what would cause this when it had compiled normally before?
THanks Bruce -
How get xml-data at servlet by http and parse it?
hello! please help me who can, i have very urgent task but not much skilful to deal with work in web. is anywhere source code or similar example of task to get xml-data at servlet by http and parse it . thank you in advance
here a basic code that reads and parses an remote xml file:
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
public class SAXParserExample extends DefaultHandler {
StringBuffer buffer;
String urlString = "http://nds.nokia.com/uaprof/NN95_8GB-1r100.xml";
public SAXParserExample() {
public void runExample() {
parseDocument();
private void parseDocument() {
// get a factory
SAXParserFactory spf = SAXParserFactory.newInstance();
try {
// get a new instance of parser
SAXParser sp = spf.newSAXParser();
URL url = new URL(urlString);
HttpURLConnection httpSource = (HttpURLConnection) url.openConnection();
// parse the file and also register this class for call backs
sp.parse(httpSource.getInputStream(), this);
} catch (SAXException se) {
se.printStackTrace();
} catch (ParserConfigurationException pce) {
pce.printStackTrace();
} catch (IOException ie) {
ie.printStackTrace();
// Event Handlers
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
System.out.println("+++ start of element: " + qName);
buffer = new StringBuffer();
public void characters(char[] ch, int start, int length) throws SAXException {
buffer.append(ch, start, length);
public void endElement(String uri, String localName, String qName) throws SAXException {
System.out.println(buffer.toString());
System.out.println("+++ end of element " + qName);
public static void main(String[] args) {
SAXParserExample spe = new SAXParserExample();
spe.runExample();
}you have only to change the urlString and adapt to your needs.
hope it helps
Maybe you are looking for
-
Flash installed, but computer doesn't show it and sites don't recognize it
I have an iMac, running Mac OSX 10.6.8, Safari browser. Have repeatedly tried to download Flash player over the last month or so - when I do, it seems to download, but then I can't find it on the computer anywhere and when I try to play videos that
-
Is it really possible to go from $0 to $200,000 in credit in 2 years?
I was reading a post on another forum where a member said that they went from $0 to $200k in credit in just two years. This was in the form of credit cards only; no loans. It was also implied that they started from scratch with no prior credit at all
-
How do I show the details of a customer when they are logged in a secure zone?
How do I show the details of a customer when they are logged in a secure zone? I want to show the customer details as well as some customer CRM fields that are applied to the customer. None of these are entered via a form, they would be entered by th
-
Updating Physical Cube Tables and Hierarchies OBIEE 11.1.1.7
OBIEE 11.1.1.7 I have imported a MSAS Cube, modeled it and created a presentation layer. I now have some new hierarchies I need to add to the phyicial layer. How do you import new Cube Tables and/or Hierarchies? When I select the Import option it cre
-
Account determination with out account keys
Can we do account determination with out account keys? and explains how?