導航:首頁 > 配伺服器 > 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伺服器地址相關的資料

熱點內容
jsp里的java 瀏覽:983
程序員合同到期不續簽賠償嗎 瀏覽:239
uc怎麼把字幕放在文件夾 瀏覽:245
buildingpdf 瀏覽:594
二分查找演算法技巧 瀏覽:196
創造與魔法游戲伺服器怎麼調 瀏覽:837
win10在cmd編譯出來空白 瀏覽:504
tif格式的壓縮包怎麼打開 瀏覽:782
pdf文檔許可權 瀏覽:72
怎麼讓手機圖片懸浮app 瀏覽:284
安卓手機粗字體怎麼設置 瀏覽:481
程序員需不需要眼鏡 瀏覽:547
經濟學pdf下載 瀏覽:750
程序員拿到offer復工 瀏覽:433
鏡像解壓一半自動斷電怎麼回事 瀏覽:987
程序員農村別墅價格 瀏覽:397
夢幻西遊網頁版通用伺服器是什麼 瀏覽:332
天天愛消除演算法 瀏覽:780
隱含模塊編譯 瀏覽:484
c語言尋路演算法 瀏覽:264