Java jsp notes and javajsp notes
I. jsp add-on worker resource Image
If you directly copy the code written on the Static Page to jsp, you will find that images cannot be loaded.
Get code:
String path = request. getContextPath ();
String basePath = request. getScheme () + ": //" + request. getServerName () + ":" + request. getServerPort () + path + "/";
Asd
<% = BasePath %>/Icons/VerifyCode.png
Ii. bug in Servlet IP Retrieval
I encountered this bug on mac OS. I don't know if this problem exists on windows.
Get user ip code:
String s = request.getHeader("X-Forwarded-For"); if (s == null || s.length() == 0 || "unknown".equalsIgnoreCase(s)) s = request.getHeader("Proxy-Client-IP"); if (s == null || s.length() == 0 || "unknown".equalsIgnoreCase(s)) s = request.getHeader("WL-Proxy-Client-IP"); if (s == null || s.length() == 0 || "unknown".equalsIgnoreCase(s)) s = request.getHeader("HTTP_CLIENT_IP"); if (s == null || s.length() == 0 || "unknown".equalsIgnoreCase(s)) s = request.getHeader("HTTP_X_FORWARDED_FOR"); if (s == null || s.length() == 0 || "unknown".equalsIgnoreCase(s)) s = request.getRemoteAddr(); if ("127.0.0.1".equals(s) || "0:0:0:0:0:0:0:1".equals(s)) try { s = InetAddress.getLocalHost().getHostAddress(); } catch (UnknownHostException unknownhostexception) { }
When the current judgment is empty, the project jumps to the last if, and the error message -->
if ("127.0.0.1".equals(s) || "0:0:0:0:0:0:0:1".equals(s)) try { s = InetAddress.getLocalHost().getHostAddress(); } catch (UnknownHostException unknownhostexception) { }
This web application instance has been stopped already. cocould not load [java.net. InetAddress].
Solution:
Open the apache-tomcat folder ----> open the conf folder ----> open the server. xml file --> <Host> Add
<Context path = "/Servlet" docBase = "/Servlet" debug = "0" reloadable = "true"/>
3. An error is reported when Ajax requests servlet
This error is reported because the interface does not support ajax request methods and adds get and post to serlvet. If you only write code in get, the get method is called in post, if you only write code in post, you can call post in get for a long time.
The above code is written in doGet. For security reasons, if we use zhong yao de jie kou, we should choose to only open the post interface because of the get interface, the request parameters can be directly spliced to the url and accessed through a browser, which is relatively insecure.