This is a headache when learning web development in the near future.
Baidu Google N Times, finally in the blog http://blog.csdn.net/liu578182160/article/details/17266879 found the root of the problem.
Development environment: Win7 32-bit flagship edition, jdk1.7_45,jre7,eclipse4.3.1 Java EE Edition, Tomcat 7.0.42,struts2.3.16.3
The problem is now that the Web. XML configuration
Original Web. xml:
<?xml version= "1.0" encoding= "UTF-8"? ><web-app id= "Struts2demo" 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 "> <filter> < filter-name>struts2</filter-name> <filter-class> Org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter </filter-class> </ filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern >/*</url-pattern> </filter-mapping></web-app>
Modified Web. xml:
<?xml version= "1.0" encoding= "UTF-8"?> <web-app version= "3.0" xmlns= "http://java.sun.com/xml/ns/ Java ee " xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance " xsi:schemalocation=" http://java.sun.com/ Xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd "> <display-name></ display-name> <filter> <filter-name>struts2</filter-name> <filter-class >org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class> </filter > <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/ *</url-pattern> </filter-mapping> <welcome-file-list> <welcome-file> login.jsp</welcome-file> </welcome-file-list> </web-app>
The key difference is the Web-app version.
(It does not seem to be the issue of this version number, just tried the 2.4 web-app, can carry out success.) )
Maybe this is not the key to the problem, where the project changes are
Original login.jsp:
<%@ page language= "java" import= "java.util.*" pageencoding= "utf-8"%><%string path = Request.getcontextpath () ; String basepath = request.getscheme () + "://" +request.getservername () + ":" +request.getserverport () +path+ "/";%> <! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" >
Login.jsp after the change:
<%@ page language= "java" contenttype= "text/html; Charset=utf-8 " pageencoding=" UTF-8 "%><% @taglib prefix=" s "uri="/struts-tags "%><! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd" >