如何在JSP页面中获取Eclipse项目的路径 [英] How to get the path of an eclipse project in jsp page
问题描述
如何获取当前项目的路径:这是一个使用maven原型创建的动态Web应用程序.
How to get the path of my current project : it's a dynamic web application created with maven archetype .
我想用scriptlet代码在jsp页面中检索路径,我使用了不同的代码,但是我总是会获取eclipse的路径(C:\ Users \ Amira \ Desktop \ eclipse \ eclipse) 或tomcat上的Web应用程序的路径((C:\ software \ apache-tomcat-7.0.28 \ apache-tomcat-7.0.28 \ wtpwebapps \ TestProjectUI)
I want to retrieve the path in my jsp page in scriptlet code , i used different codes but i'm always getting the path of eclipse (C:\Users\Amira\Desktop\eclipse\eclipse) or the path of the web application on tomcat ((C:\software\apache-tomcat-7.0.28\apache-tomcat-7.0.28\wtpwebapps\TestProjectUI)
但是我想要项目在我的工作空间中的路径:C:\ Users \ Amira \ junoWorkspace \ TestProjectUI
but i want the path of the project in my workspace : C:\Users\Amira\junoWorkspace\TestProjectUI
任何想法都会受到赞赏 谢谢
Any idea will be appreciated Thank you
这是我的jsp:
<body>
<%
if (request.getParameter("btnSubmit") != null) //btnSubmit is the name of your button,not id of that button.
{
String className = request.getParameter("testclass");
System.out.println(className);
String[] command = {"CMD", "/C", "mvn -Dtest=" + className + " test"};
ProcessBuilder probuilder = new ProcessBuilder(command);
//You can set up your work directory
probuilder.directory(new File("C:\\Users\\Amira\\junoWorkspace\\TestProjectUI"));
Process process = probuilder.start();
//Read out dir output
java.io.InputStream is = process.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String line;
System.out.printf("Output of running %s is:\n", Arrays.toString(command));
while ((line = br.readLine()) != null) {
System.out.println(line);
}
//Wait to get exit value
try {
int exitValue = process.waitFor();
System.out.println("\n\nExit Value is " + exitValue);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
%>
<html:file properties="tonFichier" name="tonForm"/>
<p> Please specify a Test :<br>
<input type="file" name="testclass" size="40" >
</p>
<div>
<input type="submit" id="btnSubmit" name="btnSubmit" value="Execute Test"/>
</div>
</form>
</body>
推荐答案
每当遇到此类问题时,我都会打印出所有System.getProperties()
,并查看是否有我想要的信息.这可能是您在此处可以做的最好的事情,因为Eclipse提供的唯一信息将通过一个属性来提供.如果您提供的属性之一中没有信息,则可以将其作为启动配置的一部分自己提供,可以在启动配置中使用workspace_loc
变量.
Whenever I have a problem like this, I print out all of the System.getProperties()
and see if there is one that has the information I want. This is probably the best you can do here, since the only information provided by Eclipse will come through a property. If you don't have the information in one of the provided properties, you can provide it yourself as part of your launch configuration, you can use the workspace_loc
variable in the launch config stuff.
这篇关于如何在JSP页面中获取Eclipse项目的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!