---
title: "Java till asp"
type: "forum-thread"
url: "https://www.webforum.nu/amne/asp/85444-java-till-asp"
topic: "ASP"
topic_url: "https://www.webforum.nu/amne/asp"
author: "henkepenke"
published: "2003-09-07T10:17:39.000Z"
updated: "2003-09-07T19:49:11.000Z"
replies: 7
views: 280
page: 1
pages: 1
language: "sv-SE"
site: "webForum — webforum.nu"
rights: "Upphovsrätten till varje inlägg tillhör dess författare."
attribution: "Citera som: webForum, https://www.webforum.nu/amne/asp/85444-java-till-asp"
---

# Java till asp

## #1 — henkepenke, 2003-09-07T10:17Z

Tja!
Vet inte om jag lagt detta inlägg rätt, men jag testar.

Jag gör ju ett statistikapplication till min sida och undrar 2 saker...

Jag vill logga upplösning och antal färger i databasen och jag har följande javascript för att få ut upplösningen:

```
<script language="JavaScript"> 
document.write(screen.width," x ",screen.height); 
</script>
```

Men hur gör jag för att de ska sparas i en variabel så att jag kan använda den? Nått sånt här menar jag...

```

<script language="JavaScript"> 
document.write(screen.width," x ",screen.height); 
</script>

upplosning = -----
```

Permalänk: https://www.webforum.nu/p/85444

## #2 — @nders, 2003-09-07T10:28Z

Du måste skicka värdena till servern på något sätt, exempelvis genom querystrings. Exempel:

```
<script language="JavaScript"> 
location.href='sidan.asp?width='+screen.width+'&height='+screen.height;
</script>
```

Sedan är det bara att på sidan.asp använda request.querystring.

mvh

Permalänk: https://www.webforum.nu/p/1149519

## #3 — henkepenke, 2003-09-07T10:38Z

En dum fråga...hur skulle den request.querystring se ut då?

Permalänk: https://www.webforum.nu/p/1149521

## #4 — @nders, 2003-09-07T10:46Z

```
intHeight = Request.Querystring ("height")
intWidth = Request.Querystring ("width")
```

Permalänk: https://www.webforum.nu/p/1149531

## #5 — henkepenke, 2003-09-07T13:13Z

Jag har såhär nu...

```
	datum = date()
	manad = Month(Now)
	ar = Year(Date) 
	dag = Day(Date)
	vecka = DatePart("ww", Date(), 2)
	tid = FormatDateTime(now,4)
	ip = Request.ServerVariables("remote_host")
	sida = Request.ServerVariables("URL")
	fran = request.servervariables("HTTP_REFERER")
	
	Function getBrowser()
	Dim Browser, ua
	
	ua = Request.ServerVariables("HTTP_USER_AGENT")
	
	If Instr(ua, "MSIE") Then
		If Instr(ua, "MSIE 6.") Then
			Browser = "Microsoft Internet Explorer 6.x"
		ElseIf Instr(ua, "MSIE 5.") Then
			Browser = "Microsoft Internet Explorer 5.x"
		ElseIf Instr(ua, "MSIE 4.") Then
			Browser = "Microsoft Internet Explorer 4.x"
		ElseIf Instr(ua, "MSIE 3.") Then
			Browser = "Microsoft Internet Explorer 3.x"
			If Instr(ua, "MSIE 3.02") Then
				Browser = "Microsoft Internet Explorer 3.02"
			End If
		Else
			Browser = "Microsoft Internet Explorer"
		End If
	ElseIf Instr(ua, "Mozilla") and Instr(ua, "compatible") = 0 Then
		If Instr(ua, "Netscape6") Then
			Browser = "Netscape Navigator 6.x"
		ElseIf Instr(ua, "Mozilla/4") Then
			Browser = "Netscape Navigator 4.x"
		ElseIf Instr(ua, "Mozilla/3") Then
			Browser = "Netscape Navigator 3.x"
		Else
			Browser = "Netscape Navigator"
		End If
	ElseIf Instr(ua, "Opera") Then
		Browser = "Opera"
	End If
	
	getBrowser = Browser
End Function

	browser = getBrowser
	
	Function getOS()
	Dim System, ua, os
	
	ua = Request.ServerVariables("HTTP_USER_AGENT")
	os = Request.ServerVariables("HTTP_UA_OS")
	
	If Instr(ua, "Windows 95") Or Instr(ua, "Win95") Then
		System = "Windows 95"
	ElseIf Instr(ua, "Win 9x 4.90") Then
		System = "Windows ME"
	ElseIf Instr(ua, "Windows 98") Or Instr(ua, "Win98") Then
		System = "Windows 98"
	ElseIf Instr(ua, "Windows 3.1") Or Instr(os, "Win16") Then
		System = "Windows 3.x/Windows NT 3.x"
	ElseIf Instr(ua, "NT 5.1") Or Instr(oa, "NT 5.1") Then
		System = "Windows XP"
	ElseIf Instr(ua, "NT 5") Or Instr(oa, "NT 5") Then
		System = "Windows 2000"
	ElseIf Instr(ua, "NT") Or Instr(oa, "NT") Then
		System = "Windows NT"
	ElseIf Instr(ua, "Mac") Then
		System = "Mac"
		If Instr(ua, "PowerPC") Or Instr(ua, "PPC") Then
			System = "Mac PPC"
		ElseIf Instr(ua, "68000") Or Instr(ua, "68K") Then
			System = "Mac 68K"
		End If
	ElseIf Instr(ua, "Linux") Then
		System = "Linux"
	ElseIf Instr(ua, "X11") Then
		System = "UNIX"
	End If
	
	getOS = System
End Function

	os = getOS%>
	
	<script language="JavaScript"> 
	location.href='dbas.asp?width='+screen.width+'&height='+screen.height;
	</script>
	<%
	intWidth = Request.Querystring ("width")
	intHeight = Request.Querystring ("height")

	upplosning = intWidth & intHeight
	
	Connect.Execute "Insert Into stats(datum,manad,dag,tid,vecka,ar,ip,sida,fran,browser,os,upplosning) Values('" & datum & "'," & manad & "," & dag & ",'" & tid & "','" & vecka & "','" & ar & "','" & ip & "','" & sida & "','" & fran & "','" & browser & "','" & os & "','" & upplosning & "')",,128
```

Men det skrivs inte ut något på upplosning i databasen. Denna filen heter dbas.asp

Permalänk: https://www.webforum.nu/p/1149577

## #6 — @nders, 2003-09-07T13:28Z

Nej, det är inte så konstigt. Först körs all asp, sedan skickas resultatet till webbläsaren, där html och javascript tolkas. 

Därför måste du ha javascriptet på den sida man kommer till som besökare, och inte göra annat än att skicka vidare till den sida som tar emot värdena och gör insert för all statistik.

Permalänk: https://www.webforum.nu/p/1149584

## #7 — Wickmark, 2003-09-07T17:56Z

Du måste ha Javascript koden längst upp, eller på en annan sida som skickar användaren till den sidan som skriver in informationen i databasen. Eller kan du ju ha de i samma sida; default.asp

```
<% if Request.QueryString("p") = "" Then %>
     <script language="JavaScript"> 
         location.href='default.asp?width='+screen.width+'&height='+screen.height;+'&p=2'
      </script>
<% elseif Request.QueryString("p") = "2" Then 
	datum = date()
	manad = Month(Now)
	ar = Year(Date) 
	dag = Day(Date)
	vecka = DatePart("ww", Date(), 2)
	tid = FormatDateTime(now,4)
	ip = Request.ServerVariables("remote_host")
	sida = Request.ServerVariables("URL")
	fran = request.servervariables("HTTP_REFERER")
	
	Function getBrowser()
	Dim Browser, ua
	
	ua = Request.ServerVariables("HTTP_USER_AGENT")
	
	If Instr(ua, "MSIE") Then
		If Instr(ua, "MSIE 6.") Then
			Browser = "Microsoft Internet Explorer 6.x"
		ElseIf Instr(ua, "MSIE 5.") Then
			Browser = "Microsoft Internet Explorer 5.x"
		ElseIf Instr(ua, "MSIE 4.") Then
			Browser = "Microsoft Internet Explorer 4.x"
		ElseIf Instr(ua, "MSIE 3.") Then
			Browser = "Microsoft Internet Explorer 3.x"
			If Instr(ua, "MSIE 3.02") Then
				Browser = "Microsoft Internet Explorer 3.02"
			End If
		Else
			Browser = "Microsoft Internet Explorer"
		End If
	ElseIf Instr(ua, "Mozilla") and Instr(ua, "compatible") = 0 Then
		If Instr(ua, "Netscape6") Then
			Browser = "Netscape Navigator 6.x"
		ElseIf Instr(ua, "Mozilla/4") Then
			Browser = "Netscape Navigator 4.x"
		ElseIf Instr(ua, "Mozilla/3") Then
			Browser = "Netscape Navigator 3.x"
		Else
			Browser = "Netscape Navigator"
		End If
	ElseIf Instr(ua, "Opera") Then
		Browser = "Opera"
	End If
	
	getBrowser = Browser
End Function

	browser = getBrowser
	
	Function getOS()
	Dim System, ua, os
	
	ua = Request.ServerVariables("HTTP_USER_AGENT")
	os = Request.ServerVariables("HTTP_UA_OS")
	
	If Instr(ua, "Windows 95") Or Instr(ua, "Win95") Then
		System = "Windows 95"
	ElseIf Instr(ua, "Win 9x 4.90") Then
		System = "Windows ME"
	ElseIf Instr(ua, "Windows 98") Or Instr(ua, "Win98") Then
		System = "Windows 98"
	ElseIf Instr(ua, "Windows 3.1") Or Instr(os, "Win16") Then
		System = "Windows 3.x/Windows NT 3.x"
	ElseIf Instr(ua, "NT 5.1") Or Instr(oa, "NT 5.1") Then
		System = "Windows XP"
	ElseIf Instr(ua, "NT 5") Or Instr(oa, "NT 5") Then
		System = "Windows 2000"
	ElseIf Instr(ua, "NT") Or Instr(oa, "NT") Then
		System = "Windows NT"
	ElseIf Instr(ua, "Mac") Then
		System = "Mac"
		If Instr(ua, "PowerPC") Or Instr(ua, "PPC") Then
			System = "Mac PPC"
		ElseIf Instr(ua, "68000") Or Instr(ua, "68K") Then
			System = "Mac 68K"
		End If
	ElseIf Instr(ua, "Linux") Then
		System = "Linux"
	ElseIf Instr(ua, "X11") Then
		System = "UNIX"
	End If
	
	getOS = System
End Function

	os = getOS
	
	intWidth = Request.Querystring ("width")
	intHeight = Request.Querystring ("height")

	upplosning = intWidth & intHeight
	
	Connect.Execute "Insert Into  stats(datum,manad,dag,tid,vecka,ar,ip,sida,fran,browser,os,u
pplosning) Values('" & datum & "'," & manad & "," & dag & ",'" & tid & "','" & vecka & "','" & ar & "','" & ip & "','" & sida & "','" & fran & "','" & browser & "','" & os & "','" & upplosning & "')",,128

   Response.Redirect("/statistics/default.asp")
end if %>
```

ett litet exempel bara  :e

Permalänk: https://www.webforum.nu/p/1149712

## #8 — UnConed, 2003-09-07T19:49Z

Istället för att skicka det med querystrings, skulle jag
lägga in dem i en cookie.. Då är de också busenkla att ta fram mha ASP. Bara ett förslag..

Permalänk: https://www.webforum.nu/p/1149798

---

Tråden på webben: https://www.webforum.nu/amne/asp/85444-java-till-asp
