导航:首页 > 配服务器 > javaweb服务器地址

javaweb服务器地址

发布时间:2022-01-13 17:56:09

1. javaweb项目中的servlet部署在服务器哪里

你这个问题不是把servlet放哪?一个页面对应N个Servlet ,servlet对应XML配置文件,你要在Tomcat的webapps下部放一个项目上去!
比如说,index.jsp页面有登录功能;访问LoginServlet;
首先webapp下的文件包目录结构应该是这样的:
项目名称(text)进去后是WEB-INF文件夹和你的页面 ,jsp。在WEB-INF里有classes这是你对应登录功能servlet的二进制文件(.class)文件 【包含包名】然后还有一个Web.xml配置文件,配置你点登录按钮时要拦截到serlvet的 <servlet> 和 <url-pattern>;如果有其他依赖包你可以在WEB-INF下建立lib文件夹将jar包拷贝到这里面来!没有跳过!

2. 如何用Java实现Web服务器

如何用Java实现Web服务器 一、HTTP协议的作用原理

WWW是以Internet作为传输媒介的一个应用系统,WWW网上最基本的传输单位是Web网页。WWW的工作基于客户机/服务器计算模型,由Web 浏览器(客户机)和Web服务器(服务器)构成,两者之间采用超文本传送协议(HTTP)进行通信。HTTP协议是基于TCP/IP协议之上的协议,是Web浏览器和Web服务器之间的应用层协议,是通用的、无状态的、面向对象的协议。HTTP协议的作用原理包括四个步骤:

(1) 连接:Web浏览器与Web服务器建立连接,打开一个称为socket(套接字)的虚拟文件,此文件的建立标志着连接建立成功。

(2) 请求:Web浏览器通过socket向Web服务器提交请求。HTTP的请求一般是GET或POST命令(POST用于FORM参数的传递)。GET命令的格式为:

GET 路径/文件名 HTTP/1.0

文件名指出所访问的文件,HTTP/1.0指出Web浏览器使用的HTTP版本。

(3) 应答:Web浏览器提交请求后,通过HTTP协议传送给Web服务器。Web服务器接到后,进行事务处理,处理结果又通过HTTP传回给Web浏览器,从而在Web浏览器上显示出所请求的页面。

3. javaweb 程序怎么知道放在哪一个服务器IP 上运行了

您好,Java语言是开源的,如果您的源码被盗用,那么随之的源码内容很可能会被修改。如果对方没有发现您内部实现的这个功能,可能您还可以发现被盗用后锁存放的ip地址,如果对方发现有这个功能,那么直接删除或者修改,您就没有办法了。如下几种方案供您参考:
1,混淆肯定要做.不然再好的保护,被反编译了,修改代码,验证的方法照样被修改取消.
2,数字签名,参照java安全机制,给你的jar签名,写自己专门的类加载classloader
3,参照单机软件保护措施,用非对称加密手段,保存自己的私钥.
4,某些lib可以运行时加载,动态加载到内存里面,静态的lib是加密的,只有解密后的lib才可以加载运行
5,jni本地方法
采用多种验证方式,多个地方验证...一般破解的受到挫折,就不干了
其实也不是很复杂,呵呵
你的web软件加上一个安装步骤,要求输入密钥,才能运行,呵呵

4. javaweb项目在配置文件中定义的localhost地址为什么会随服务器的不同而改变

myproperties.getlocalhost这个取得是配置文件里的值吧,你全局搜索下配置文件,以 .properties结尾的,这些都是配置好的

5. java 怎么获取服务器webroot的路径

使用JAVA后台代码取得WEBROOT物理路径,可以有如下两种方式:
1、使用JSP Servlet取得WEB根路径可以用request.getContextPath(),相对路径request.getSession().getServletContext().getRealPath("/"),它们可以使用我们很容易取得根路径。

2、如果使用了spring, 在WEB-INF/web.xml中,创建一个webAppRootKey的param,指定一个值(默认为webapp.root)作为键值,然后通过Listener,或者Filter,或者Servlet执行String webAppRootKey = getServletContext().getRealPath("/"); 并将webAppRootKey对应的webapp.root分别作为Key,Value写到System Properties系统属性中。之后在程序中通过System.getProperty("webapp.root")来获得WebRoot的物理路径。
具体示例代码如下:
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<context-param>
<param-name>webAppRootKey</param-name>
<param-value>csc2.root</param-value>
</context-param>
<listener>
<listener-class>test.ApplicationListener</listener-class>
</listener>
</web-app>

ApplicationListener.java
package test;
import javax.servlet.ServletContextEvent;
import org.springframework.web.context.ContextLoaderListener;
public class ApplicationListener extends ContextLoaderListener {
public void contextDestroyed(ServletContextEvent sce) {
// TODO Auto-generated method stub
}
public void contextInitialized(ServletContextEvent sce) {
// TODO Auto-generated method stub
String webAppRootKey = sce.getServletContext().getRealPath("/");
System.setProperty("csc2.root" , webAppRootKey);
String path =System.getProperty("csc2.root");
System.out.println("sssss:::"+path);
}
}

test.java
public class test {
public void remve(){
String path =System.getProperty("csc2.root");
System.out.println("result::::::::"+path);
}

}

index.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="java.util.*" %>
<%@ page import="test.test" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%
test t = new test();
t.remve();
%>
<html>
</html>
部署程序发布 启动TOMCAT 运行index.jsp 就可以调用JAVA中全局设置的物理路径了(说明这里的JSP 只是调用了TEST.JAVA 的remove方法,不做其他使用。原理解释,TOMCAT启动和读取WEB.XML 监听方式加载SPRING ApplicationListener继承SPRING ContextLoaderListener加载SPRING顺便吧全局路径赋值给csc2.root 描述,这样之后JAVA 代码中就可以使用System.getProperty("csc2.root")调用全路路径了。

6. java 如何配置web服务器

JavaWeb Tomcat服务器配置过程如下:

Tomcat服务器端口的配置

Tomcat的所有配置都放在conf文件夹之中,里面的server.xml文件是配置的核心文件。如果想修改Tomcat服务器的启动端口,则可以在server.xml配置文件中的Connector节点进行的端口修改

例如:将Tomcat服务器的启动端口由默认的8080改成8081端口

Tomcat服务器启动端口默认配置

1 <Connector port="8080" protocol="HTTP/1.1"

2 connectionTimeout="20000"

3 redirectPort="8443" />

将Tomcat服务器启动端口修改成8081端口


1 <Connector port="8081" protocol="HTTP/1.1"

2 connectionTimeout="20000"

3 redirectPort="8443" />

这样就把原来默认Tomcat默认的的8080端口改成了8081端口了,需要注意的是,一旦服务器中的*.xml文件改变了,则Tomcat服务器就必须重新启动,重新启动之后将重新读取新的配置信息。因为已经在server.xml文件中将Tomcat的启动端口修改成了8081,所以Tomcat服务器启动时就以8081端口启动了,如下图所示:

7. JAVA的web项目(demo04_test)部署之后,其中login.jsp页面在浏览器中访问地址是什么(tomcat服务器)

地址应该是:localhost:8080/demo04_test/jsp/user/login.jsp
其中8080是tomcat默认的端口号,如果你改过了,那就把你的8080改成你自己改的那个端口

8. Java Web服务器

我现写了一个,可以访问到静态资源。你看情况多给点分吧
另外eclipse还没有5.5,5.5的貌似是myEclipse吧

其中port指端口,默认是地址是http://127.0.0.1:8088/
其中basePath指资源根路径,默认是d:
可以通过命令行参数对其进行赋值

import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.URLDecoder;

public class SimpleHttpServer {
private static int port = 8088;
private static String basePath = "D:/";

public static void main(String[] args) {
if (args.length >= 1) {
basePath = args[0];
}
if (args.length >= 2) {
port = Integer.parseInt(args[1]);
}
System.out.println("server starting:");
System.out.println("base path:" + basePath);
System.out.println("Listening at:" + port);
startServer();
System.out.println("server started succesfully");
}

private static void startServer() {
new Thread() {
public void run() {
try {
ServerSocket ss = new ServerSocket(port);
while (true) {
final Socket s = ss.accept();
new Thread() {
public void run() {
try {
OutputStream socketOs = s.getOutputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(s.getInputStream()));
String line;
String headerLine = null;
while ((line = br.readLine()) != null) {
if (headerLine == null) {
headerLine = line;
}
if ("".equals(line)) {
break;
}
}
String target = headerLine.replaceAll("^.+ (.+) HTTP/.+$", "$1");
String queryString;
String[] tmp = target.split("\\?");
target = URLDecoder.decode(tmp[0], "utf-8");
target = target.endsWith("/") ? target.substring(0, target.length() - 1) : target;
if (tmp.length > 1) {
queryString = tmp[1];
} else {
queryString = "";
}

String filePath = basePath + target;
File f = new File(filePath);

if (!f.exists()) {
StringBuffer content = new StringBuffer();
content.append("<html><head><title>Resource Not Found</title></head><body><h1>The requested resource ")
.append(target).append(" is not found.</h1></body></html>");
StringBuffer toWrite = new StringBuffer();
toWrite.append("HTTP/1.1 404 Not Found\r\nContent-Length:").append("" + content.length()).append("\r\n\r\n")
.append(content);
socketOs.write(toWrite.toString().getBytes());
} else if (f.isDirectory()) {
StringBuffer content = new StringBuffer();
content.append("<html><head><title>").append(target).append(
"</title></head><body><table border='1' width='100%'>");
content.append("<tr><th align='left' width='40px'>").append("Path").append("</th><td>").append(target.length()>0?target:"/")
.append("</td></tr>");
content.append("<tr><th align='left'>Type</th><th align='left'>Name</th></tr>");
if (!basePath.equals(filePath)) {
content.append("<tr><td>Directory</td><td>").append("<a href='").append(
target.substring(0, target.lastIndexOf("/") + 1)).append("'>..</a>").append("</td></tr>");
}
File[] files = f.listFiles();
for (File file : files) {
content.append("<tr><td>");
if (file.isFile()) {
content.append("File</td><td>");
} else if (file.isDirectory()) {
content.append("Directory</td><td>");
}
content.append("<a href=\"").append(target);
if (!(target.endsWith("/") || target.endsWith("\\"))) {
content.append("/");
}
content.append(file.getName()).append("\">").append(file.getName()).append("</a></td></tr>");
}
content.append("</table></body></html>");

StringBuffer sb = new StringBuffer();
sb.append("HTTP/1.1 200 OK\r\nCache-Control: max-age-0\r\n");
sb.append("Content-Length:").append("" + content.length()).append("\r\n\r\n");
sb.append(content);
socketOs.write(sb.toString().getBytes());
} else if (f.isFile()) {
socketOs.write(("HTTP/1.1 200 OK\r\nCache-Control: max-age-0\r\nContent-Length:" + f.length() + "\r\n\r\n")
.getBytes());
byte[] buffer = new byte[1024];
FileInputStream fis = new FileInputStream(f);
int cnt = 0;
while ((cnt = fis.read(buffer)) >= 0) {
socketOs.write(buffer, 0, cnt);
}
fis.close();
}
socketOs.close();
} catch (Exception e) {
try {
s.getOutputStream().write("HTTP/1.1 500 Error\r\n".getBytes());
ByteArrayOutputStream byteos = new ByteArrayOutputStream();
PrintStream printStream = new PrintStream(byteos);
printStream
.write("<html><head><title>Error 500</title></head><body><h1>Error 500</h1><pre style='font-size:15'>"
.getBytes());
e.printStackTrace(printStream);
printStream.write("</pre><body></html>".getBytes());
byteos.close();
byte[] byteArray = byteos.toByteArray();
s.getOutputStream().write(("Content-Length:" + byteArray.length + "\r\n\r\n").getBytes());
s.getOutputStream().write(byteArray);
s.close();
} catch (IOException e1) {
e1.printStackTrace();
}

}
}
}.start();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}.start();
}
}

9. 求教java web 在服务器上获取路径问题

归根结底,Java本质上只能使用绝对路径来寻找资源。所有的相对路径寻找资源的方法,都不过是一些便利方法。不过是API在底层帮助我们构建了绝对路径,从而找到资源的!
在开发Web方面的应用时, 经常需要获取 服务器中当前WebRoot的物理路径。
如果是Servlet , Action , Controller, 或则Filter , Listener , 拦截器等相关类时, 我们只需要获得ServletContext, 然后通过ServletContext.getRealPath("/")来获取当前应用在服务器上的物理地址。
如果在类中取不到ServletContext时, 有两种方式可以做到:
1. spring框架的思路, 在WEB-INF/web.xml中 , 创建一个webAppRootKey的param, 指定一个值(默认为webapp.root)作为键值, 然后通过Listener , 或者Filter , 或者Servlet 执行String webAppRootKey = getServletContext().getRealPath("/"); 并将webAppRootKey对应的webapp.root 分别作为Key , Value写到System Properties系统属性中。之后在程序中通过System.getProperty("webapp.root")来获得WebRoot的物理路径。
2. 利用Java的类加载机制 调用 XXX.class.getClassLoader().getResource(""); 方法来获取到ClassPath , 然后处理获得WebRoot目录,这种方式只能是该class在WebRoot/WEB-INF/classes下才能生效, 如果该class被打包到一个jar文件中, 则该方法失效。这时就应该用下面一种方式。
根据第二种的思路,我们还可以再扩展一下。不过对于在部署在一台服务器中的应用来说,若还不是你所需请再往下看。
下面是一些得到classpath和当前类的绝对路径的一些方法。你可使用其中的一些方法来得到你需要的资源的绝对路径:
1. DebitNoteAction.class.getResource("")
得到的是当前类FileTest.class文件的URI目录。不包括自己!
如:file:/D:/eclipse/springTest/WebRoot/WEB-INF/classes/
atacarnet/src/com/evi/moles/atacarnet/action/
2. DebitNoteAction.class.getResource("/")
得到的是当前的classpath的绝对URI路径。
如:file:/D:/eclipse/springTest/WebRoot/WEB-INF/classes/
3. Thread.currentThread().getContextClassLoader().getResource("")
得到的也是当前ClassPath的绝对URI路径
如:file:/D:/eclipse/springTest/WebRoot/WEB-INF/classes/
4. DebitNoteAction.class.getClassLoader().getResource("") 或ClassLoader.getSystemResource("")
得到的也是当前ClassPath的绝对URI路径。

10. java 如何获取webcontent的路径 不是tomcat服务器的路径

用servlet获取
1、获取项目的绝对路径
request.getSession().getServletContext().getRealPath("")
结果:
E:\java_web\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\myWebsite
2、获取浏览器地址
request.getRequestURL()
结果:
http://localhost:8080/myWebsite/QuestionServlet
3、获取当前文件的绝对路径
request.getSession().getServletContext().getRealPath(request.getRequestURI())
结果:
E:\java_web\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\myWebsite\myWebsite\QuestionServlet

阅读全文

与javaweb服务器地址相关的资料

热点内容
iphone6s照片压缩 浏览:68
中国龙文件夹名字 浏览:95
加法是运算法则 浏览:33
linuxvim命令查找 浏览:948
linuxhttp端口 浏览:907
程序员去国企 浏览:632
android自动刷新listview 浏览:572
美国寿力压缩机 浏览:546
如何查看公司服务器的配置 浏览:348
得到app的文章怎么复制 浏览:382
程序员创业规模 浏览:377
java文件排序算法 浏览:239
民政低保对象app邮箱怎么填 浏览:948
jsp里的java 浏览:983
程序员合同到期不续签赔偿吗 浏览:239
uc怎么把字幕放在文件夹 浏览:245
buildingpdf 浏览:594
二分查找算法技巧 浏览:196
创造与魔法游戏服务器怎么调 浏览:837
win10在cmd编译出来空白 浏览:504