Using %=request.getContextPath()% path in .js file.?
Hi,
I was using java script code in my JSP itself.This was working fine.but when i moved the code in .js file,it stopped working.!!!.
Please suggest how to make it work.
Cheers:
Akash.
<%=request.getContextPath()%> won't work in a .js file. You can use a JSP file to generate javascript code by using content-type attribute of the page directive. To call this JSP page (which will actually generate the js code), you can either map the JSP page to a .js file in web.xml or use the URL to that JSP page directly in your JSP page where you are including that .js file. Basically this is what I mean
<script type="text/javascript" src="myjs.jsp"></script>Use the above in your calling page or the below (along with the mapping in your web.xml)
<script type="text/javascript" src="myjs.js"></script>web.xml
<servlet>
<servlet-name>MyJs</servlet-name>
<jsp-file>/myjs.jsp</jsp-file>
</servlet>
<servlet-mapping>
<servlet-name>MyJs</servlet-name>
<url-pattern>/myjs.js</url-pattern>
</servlet-mapping>
Similar Messages
-
Using Request Response Bean Module in FILE Adapter
Hi Experts,
Can we use Request Response Bean Module in FILE Adapter in reverse way. That is can we configure thses adapter modules in Reciever file channel and call a sender file channel in it?
My case is RFC to File synchronous case? How do we do this?
Thanks & Regards,
priyankaCan we use Request Response Bean Module in FILE Adapter in reverse way. That is can we configure thses adapter
modules in Reciever file channel and call a sender file channel in it?
My case is RFC to File synchronous case? How do we do this?
The above is not possible....Bean works only for Sender channel and not for Receiver.....requirement not possible using even a BPM as FILE does not support SYNC communication in receiver end......max you can do is split the scenario into SYNC-ASYNC bridge.
Regards,
Abhishek. -
Hi all,
when a create a SQL Server Project using "File > New ...", I find the following settings defaulted:
SQL Server is (local)\Version12.0 and
DefaultDataPath, DefaultFileprefix and the DefaultFilename(s) for MDFs and LDFs point to the Project directory.
Initial settings of file size and increments are also not settable but defaulted.
Because my projects have to verify performance by testing with large volume of data, we have to use a different SQL Server with files stored on that Server. The Project settings have a button to changes DB properties, but these are not part of that
dialog.
So I spent some fruitless hours in vain to find a way to change the project's connection to my development SQL Servers.
How to cope with that?
Thanks in advance.
Regards UweHi Caillen,
thanks for Your response. I have to apologize for being a little late with my answer. I'll try to clarify my case more precisely:
This is surely a topic related to VS2013 handling new "SQL Server Database Projects". When one clicks "OK" the following steps are executed by VS2013 (surely controlled by standard templates or the like):
VS2013 creates the new project in a selectable directory and uses the projectname as a subdirectory whre the directory elements (*.sqlproj, bin\, obj\) where later all the *.sql are placed, too. This is normal and expected.
VS2013 creates a new database with its DB-files
and attaches it to "(localdb)\ProjectsV12". The name of the database is the name of the project. The path to the DB-files (*.mdf and ldf) and their sizes are also defaulted to small values. The DB-server and the
path to the DB-files is taken from the registry (!) HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\12.0\SSDT\LocalDbDatabaseFilePaths. I don't know when and by what tools these values are set.
The path to DB-Files is typically also the path to the projects. The (local)-server places all system database files in the User\<user-ID>\Appdata\.. tree. Which is OK for small databases. The templates extracts some data from the DB-file path and
places it in the deployment SQLs to populate the SQLCMD variables DefaultDataPath, DefaultFileprefix and the DefaultFilename(s) which are generated when pressing "Executed" or "Debug" the project.
My problem is that we have to test database performance with larger volumes of data (e.g. two million rows and more). These cannot be stored in the User-path but must be handled by some kind of professional DB-Manager on various storage devices. When everything
is tested, the publishing function of VS2013 will extract the structure and you are done incl. all the performance taming things.
The dialog from the project properties can change to a different Server, but that server does not know your project database. The server and the DB-Files should be specified by the developer before VS2013 creates the database.
So the right forum would be a forum, where people developing SQL Server solutions with VS2013 are reading the questions.
Thanks again for your patience.
Regards Uwe -
Is request.getContextPath() necessary?
I used to start a URL with request.getContextPath() for navigating any JSP files inside of the application. Since I can't pass it into a Javascript, I have a URL without it. The approach seems working so far. Does that mean that it isn't necessary to start a URL with request.getContextPath() ?
Using request.getContextPath() is handy if you are running a webapp that is not at the root context. For example, you can have 1 application running at the root context with 5 other apps on the same url running under their own context path - 1 url : multiple apps.
How your app is setup depends on how you use request.getContextPath(). For instance I use it frequently for path references in html snippets in my JSPs:
<script src="<%=request.getContextPath()%>/scripts/myDateFunction.js"></script>
<link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/styles.css">Now no matter what context this runs under, I'll be garanteed it will look for the file under the requested context at it's root context:
http://localhost:8080/ = root context = "/"
http://localhost:8080/myApp/ = webapp "myApp" = "myApps" root context is "/myApp" + "/"
scripts lives in myApp:
myApp.war
-> /scripts/myDateFunctions.js
If I were to move my web application to a different context then I don't need any code changes as the request will always retrieve for me the correct context.
You can't exactly pass it to Javascript, but you can embed it in the javascript:
<script language="Javascript">
function goPage(pageName) {
document.location="<%=request.getContextPath()%>/admin/myPage.jsp";
</script>When the server writes this to the browser it will replace the <%=request.getContextPath()%> with the correct value.
Regards,
Anthony -
How to get a list of file paths for all files used in a project
I have a project in Premiere Pro CC which has a large number of bins. A sequence in one of these bins uses files from other bins. I am trying to find the locations of all each of the files used in the project.
1) Obviously I can select each clip in the timeline and show in finder, but there a lot of clips
2) The video usage associated with each file in the project would help. However
1. I haven't found a way to display only clips that have video useage if all of the bins have not been expanded.
2. Video usage shows usage for all sequences, so one would have to manually check the pull down for each file to see if it is used in the sequence in question.
3) I tried exporting the project to final cut pro xml. The path url gives me the information that I need. For some reason, however, when I do the export only one clip's information is there, not the information for all of the other clips in the project.
4) I tired an export for speedgrade and all of the file names are there. However the paths are not.
Basically I want to find all of the files in the project and relocate them to a specific folder for that project. There's got to be a way to do this but I'm not seeing it ....Thanks for the suggestion concerning the file path. And certainly it would have been nice to have done this before beginning. However this is a project that has been around for quite a while, and the files have been moved into different bins. And now the project sequence is being revised.
So the problem is, worded slightly differently, how can I search all of the bins for the files that are used just by this sequence, ignoring the files which are used by other sequences? Or, how can I get a list of the file paths of the files that are used in the sequence? -
Hi, there
I'm not really pro- at RDS in server 2012 (r1), but I have a problem and don't find anything suitable on internet:
I'm trying to publish one of my own, unlisted programs to rdweb, but it keeps saying "You must specify a file from the RD Session Host server SERVERNAME by using the UNC path...."
1) I provided the path in the unc name - when I click "Add.." then i browse the the .exe file via network share, not via local path. So that should be OK
2) Firewall is turned off and eventhough the exeptions are enabled, both of then, checked
What else should I do to make this work?Okej, I found the sollution:
You have to specify the path like \\hostname\drive_letter$\path-to-the-program.
I was doing wrong because i wrote it like \\hostname\ShareName\path-to-the-program.
I was misleded because the wizard wants me to find the program by clicking, and not by entring the path manualy. -
How to get the complete path of the file that is selected using FormFile
i m working on struts..
i hv used FormFile like
<html:file property="xsdpath" value="Browse" />
need to get the whole path that i will select using browse button
for example d:\foldername\filename.java
but FormFile Api has a method getFileName(); which returns the filename, for getting the absolute path wat has to be done.
please reply bak soon
thanks in advancehere i use formfile <html:file> just to allow the
user to select a xml file .
so i need to get the whole path of the selectedfile
to parse the xml file.No you dont.
You would definitely benefit from further reading on
file upload.
<html:file> tag renders an HTML <input> element of
type file.
When a user uploads a file, this file is sent as a
stream of data, which a program (jsp/servlet) on the
server, reads and stores the data back in the form
of a file on the server.
Any server program that needs to parse the file,
should do so on the file stored on the server.
There's no point in knowing the absolute path of the
file on the client machine. If a server program can
parse a file on the client machine, why upload the
file in first case ? Get the drift ?
i also want to show my user the path he hadselected.
If you have such a requirement, then yes.
But it sounds weird to me. If you see my response
above, you will realize that the server has a copy of
the client's file uploaded and then parsed. What if
the client has changed his file after upload ?
cheers,
ram.I also have a requirement to get the whole filepath of the file selected and place this information into a table. From FormFile I can only retreive the absolute filename
Any suggestions would be helpful.
Thanks, dam -
Finding the exact path of a file using a Java program
Can anyone tell me how to find the exact path of a file which is saved in a directory other than the one in which the main file is saved? I know there is a class called File which has many methods like isAbsolutePath() and isPath() but they return the path in which the main class is located
actually i m trying to write a program which will
take a name of a file or a directory from the console
and it should give the entire path of that file or
directory and this file need not be stored in the
path of the main class.....It can be stored in any
drives of my PC....Ok, then the console input needs to be an absolute path or a path relative to some given directory (usually the one from which the application is started). Java cannot magically guess absolute paths if you just provide a file name. E.g. if I'd use your program and would provide as input "build.xml", how should the program know which file by that name I mean (there are lots of build.xml files in different locations on my machine)? -
How to get full path of a file uploaded using file control on a jsp ?
Hi all...
I have a jsp on which i am using a file element (input type="file") to upload files present on the physical file system.. Thats working fine.. But i want to retrieve the full path of the file uploaded for further computation.
What are the possible ways which can give me the full path ?? (e.g. "D:\data\text\Output.txt" )
Thanks all for attending the question..
Regards
PrasadSome browsers send the full path. Some do not.
You can not affect this in any way shape or form.
All you can count on receiving is a filename - no path information.
So you will have to have some other way for the user to pass along this information.
If they are uploading to a "remote web site" they could specify a folder to put the uploaded file in.
You could classify it and put all image files in "images" and all script files in "scripts" etc etc by default, and let the user deal with it in their own HTML.
Hope this helps,
evnafets -
How 2 get the path of a file Using jsp
how 2 get the path of a file Using jsp
i have tried getPath...but i'm geting the error
The method getPath(String) is undefined for the type HttpServletRequest
any idea how 2 get the path of a fileYou need ServletContext#getRealPath().
API documentation: http://java.sun.com/javaee/5/docs/api/javax/servlet/ServletContext.html#getRealPath(java.lang.String) -
How to handle spaces in using path to the file
Hi Friends,
I am getting error "file not found" if I give path of the file that contains spaces in it. (eg. C:\Users\Sample Project\file.txt)
If I give path that doesn't contain spaces (eg. C:\Users\Sample\file.txt) then it works fine without any error.
Basically I am invoking one command at runtime (using "exec") in my java program that excepts path of the file as one parameter.
I can't remove space by manipulating path - othewise that path will be different.
How can I solve this issue?
ThanksWorks for me:
import java.io.*;
public class ProcessExample {
public static void main(String[] args) throws IOException {
if (args.length == 0) {
Runtime r = Runtime.getRuntime();
dump(r.exec("java ProcessExample foo \"bar baz\""));
} else {
for(String s : args) {
System.out.println(s);
static void dump(Process p) throws IOException {
BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream()));
for(String s; (s = r.readLine()) != null; ) {
System.out.println("[" + s + "]");
}But ejp's advice is even better. -
Getting absolute path of a file in a webapp without using servlet/JSP
Hi all,
I need a small clarification. Is it possible to reterive the absolute path of a file present in a tomcat web application without using Servlet/JSP. I have a normal java class which uses this file to read the configuration parameters. I like to know whether I need to create a seperate servlet which will read the parameters from web.xml.Hi all,
I need a small clarification. Is it possible to
reterive the absolute path of a file present in a
tomcat web application without using Servlet/JSP. What if the file is in a WAR? What do you do then?
I
have a normal java class which uses this file to
read the configuration parameters. There are other, better ways to do this.
I like to know
whether I need to create a seperate servlet which
will read the parameters from web.xml.What do you really want it for? You shouldn't need an absolute path. Use the class loader to get an InputStream.
% -
How to use Class-Path in Manifest file
hi,
I want to add jar files in another executable jar file but the Class-Path in Manifest file is not set correctly,please give an example for setting a Class-Path attribute in Manifest class.
regards,
selvarajYou looked into the Jar section of the Sun tutorial did you?
-
Unable get complete filepath from jsp page using request.getParameter()
Hey all,
i am actually trying to get the selected file path value using request.getParameter into the servlet where i will read the (csv or txt) file but i dont get the full path but only the file name(test.txt) not the complete path(C:\\Temp\\test.txt) i selected in JSP page using browse file.
Output :
FILE NAME : TEST
FILE PATH : test.txt
Error : java.io.FileNotFoundException: test.txt (The system cannot find the file specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:106)
at java.io.FileReader.<init>(FileReader.java:55)
at com.test.TestServlet.processRequest(TestServlet.java:39)
at com.test.TestServlet.doPost(TestServlet.java:75)
JSP CODE:
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>DEMO SERVLET</title>
</script>
</head>
<body>
<h2>Hello World!</h2>
<form name="myform" action="TestServlet" method="POST"
FILE NAME : <input type="text" name="filename" value="" size="25" /><br><br>
FILE SELECT : <input type="file" name="myfile" value="" width="25" /><br><br>
<input type="submit" value="Submit" name="submit" />
</form>
</body>
</html>
Servlet Code :
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException, FileNotFoundException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
try {
String filename = request.getParameter("filename");
out.println(filename);
String filepath = request.getParameter("myfile");
out.println(filepath);
out.println("<html>");
out.println("<head>");
out.println("<title>Servlet TestServlet</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>Servlet TestServlet at " + request.getContextPath() + "</h1>");
if (filepath != null) {
File f = new File(filepath);
BufferedReader br = new BufferedReader(new FileReader(f));
String strLine;
String[] tokens;
while ((strLine = br.readLine()) != null) {
tokens = strLine.split(",");
for (int i = 0; i < tokens.length; i++) {
out.println("<h1>Servlet TestServlet at " + tokens[i] + "</h1>");
out.println("----------------");
out.println("</body>");
out.println("</html>");
} finally {
out.close();
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
Needed Output :
FILE NAME : TEST
FILE PATH : C:\\Temp\\test.txt
Any suggestions Plz??As the [HTML specification|http://www.w3.org/TR/html401/interact/forms.html] states, you should be setting the enctype to multipart/form-data to be able to upload files to the server. In the server side, you need to process the multipart/form-data binary stream by parsing the HttpServletRequest#getInputStream(). It is a lot of work to get it to work flawlessly. There are 3rd party API's around which can do that for you, such as [Apache Commons FileUpload|http://commons.apache.org/fileupload] (carefully read the User Guide how to use it).
You can also consider to use a Filter which makes use of the FileUpload API to preprocess the request so that you can continue writing the servlet code as usual. Here is an example: [http://balusc.blogspot.com/2007/11/multipartfilter.html]. -
How to get the Real Path of a file which is accessed by URL?
iam using tomcat6.0.
I have a file xyz.xml at the top of the webapplication HFUSE which i can able to access by URL
http://localhost:8080/HFUSE/xyz.xml
My problem is how to get the realpath of the file "xyz.xml" for reading and writing purposes.
I tried various things but i could not able to successfully solved the problem?
1) File f = new File("/xyz.xml");
print(f.getAbsolutePath()) ============== it is not fetching the file @ http://localhost:8080/HFUSE/xyz.xml rather it is creating a file
at the root of the drive where eclipse is running.
2) File f = new File("xyz.xml");============> this is also not working , it is creating the file xyz.xml in the eclipse directory ..................
Can anyone please guide on this problem?RevertInIslam wrote:
If you want your context root(i.e HFUSE)
use this:
request.getContextPath() //where request is HttpServletRequest object to get the needful path.
e.g:
File f = new File(request.getContextPath()+"/xyz.xml");//it will create the file inside HFUSE.
Hope this helps.
Regards
BWrong. The File constructor expects an absolute filesystem path. The HttpServletRequest#getContextPath() doesn't return the absolute filesystem path, it only returns the relative path from the current context root. Use ServletContext#getRealPath() instead, it returns the absolute filesystem path for the given relative path from the current context root.
File file = new File(servletContext.getRealPath("/"), "xyz.xml");
Maybe you are looking for
-
My external hard drive crashed and that is where I had all of my music/media files. I do have some content on another external drive, but not all (and not my movies, etc). How can I copy everything, from my ipod classic, back to my itunes on my PC w
-
Highlighting in Adobe Reader 9? I've already enabled highlighting but it does not work!
I've already followed the steps posted here: http://forums.adobe.com/thread/430906 and enabled highlighting under preferences but i'm still unable to highlight or comment. I am sure the document allows commenting as I was able to highlight and commen
-
Applications not hiding when I click on desktop
Forgive me for not searching I'm brand new I swear that when I used to click on the desktop behind any of my open applications, the desktop would instantly show and whatever application was on top would instantly hide. Now whenever I click on the des
-
Flow chart ...from Vi hierarchy??
I know I've gone about this the wrong way...probably item #1 in the top ten things not to do when programming but... (I'm not a software engineer, have you guessed?) I have a fairly complex state machine vi developed and deployed and I don't have a
-
Trouble Opening Email Attachments
I am having problems opening email attachments. These attachments are .doc, .pdf and .xls files that used to open. They come across as winmail.dat files and won't open. Any ideas?