Coding and Path Problems in Java Web

Source: Internet
Author: User

 

Coding problems in Java Web: 1. the following method is generally used to obtain the passed Chinese characters when passing values through get: string name = new string (request. getparameter ("name "). getbytes ("ISO-8859-1"), "UTF-8 "); in this way, the original Chinese characters can be obtained after the uploaded values are encoded twice. Another simple method is in Tomcat/config/server. xml configuration: <connetor Port = "8080" protocol = "HTTP/1.1" connectortimeout = "2000" uriencoding = "UTF-8"> 2. the first method can also be used to solve the value passed by post, but there is also a simple method: In reqeust. setcharacterencoding ("UTF-8"); Path Problems in Java Web: 1. web. the path in XML is in the web. when configuring the URL-pattern path in XML, you must add/in front of it, and this/is relative to context-path, that is, the path of/index: http: // localhost: 8080/nyist/index2. path in the foreground HTML is in the path representation in HTML./indicates the service root path. You can also use the relative path in HTML, it is necessary to perform relative positioning based on all the URL paths of the current HTML page (whether it is the <A> link or the action in form is the same as 0) 3. the path in the servlet is accessed relative to context-path. you can locate the target Servlet Path Based on the URL path of the current serlvlet. for the request. getrequestdispatcher (".. /.. /admin/art/Index "). forward (request, response); The problem can also be located based on the utrl relative path. Note: For resonse. for sendredirect ();, It is the browser's redirection, where/is relative to the server root, while forward is relative to context-Path

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.