Java jsp notes and javajsp notes

Source: Internet
Author: User

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.

 

 

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.