问题1:
我用的是myeclipse2017在新建web项目的时候出现了一个问题:
是新建web project 还是新建web service project?
一开始我建的是后者 然后发现不对 :
1、当你是web应用时,比如说要建个网站,需要发布到服务器时,应该要建Web Project
2、当你是做分布式系统时,也就是你做的只是一个服务,对外发布也只是一个服务的时候,需要建立Web Services Project(不理解可以先研究下webservices)
3、当你仅仅是需要JDK来运行一些本地代码的时候,只需要建Java Project就可以啦饿
web service project 在你建项目的时候加web service实现的包
原文:https://blog.csdn.net/xiaxiaorui2003/article/details/4276096
问题2:
在新建jsp时有两种jsp
一种是jsp(Advanced Templates)
第二种jsp(Basic Templates)
选的是第二种
问题3:
我把web.xml、struts.xml、demo1.jsp中的所有编码都改成了 UTF-8
问题4:
配置web.xml出现的问题 因为我的demo没有自动生成web.xml,所以我就从C:\apache-tomcat-8.5.34\webapps\struts2-blank\WEB-INF下边复制了一个web.xml 内容如下:
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_9" 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">
<display-name>strut2_day0</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>index.html</welcome-file>
</welcome-file-list>
<!-- Restricts access to pure JSP files - access available only via Struts action -->
<security-constraint>
<display-name>No direct JSP access</display-name>
<web-resource-collection>
<web-resource-name>No-JSP</web-resource-name>
<url-pattern>*.jsp</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>no-users</role-name>
</auth-constraint>
</security-constraint>
<security-role>
<description>Don't assign users to this role</description>
<role-name>no-users</role-name>
</security-role>
</web-app>
然后进行了运行 发现出现了了 403Forbidden 错误
403 Forbidden的出现情况一般为:
1.未获得文件系统的访问授权
2.访问权限出现了某些问题(从未授权的发送源ip试图访问)
由于是从本地访问 应该是第一种情况
从网上查到了解决的方法:
把除了 和的其余部分都删掉即可,如下:
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_9" 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">
<display-name>strut2_day0</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>
</web-app>
然后就可以正确运行了:)