1.Eclipse重新安装tomcat后项目中所有import javax.servlet.*报错
解决方法:项目名右键,选择Build Path->Configure Build Path找到 Targeted Runtimes,选择新安装的tomcat,Apply刷新项目,红叉消失.
2.解决在eclipse中删除tomcat server后导致无法重新添加服务器的问题
在文件夹中进入到以下目录:workspace\.metadata\.plugins\org.eclipse.core.runtime\.settings然后找到org.eclipse.jst.server.tomcat.core.prefs文件并打开,删除里面之前创建的tomcat信息并保存
同样找到org.eclipse.wst.server.core.prefs并打开,删除里面之前创建的tomcat信息并保存
这两文件只需要保留eclipse.preferences.version=1即可
或者可以直接删除org.eclipse.wst.server.core.prefs和org.eclipse.jst.server.tomcat.core.prefs这两个文件,再重启eclipse即可.
2020.9.23 tomcat保存:双机tomcat给第一项打勾
- 对于一个servlet多个连接中的servlet配置问题
首先doget后添加dopost dopost中的doget注释掉(对于doget请求)
- MVC设计模式修改操作中回显问题出现空指针异常
问题在于同名字提交导致customer无法获取导致无id传入,出现空指针异常,解决方案:在jsp中customer的初始化前先把数据赋值
id = customer.getId()+"";
Type mismatch: cannot convert from Integer to String
不加”” id 是String customer.getId()为int类型的。
String id = null;
String name = null;
String oldName = null;
String address = null;
String phone = null;
Customer customer = (Customer) request.getAttribute("customer");
if(customer!=null){
id = customer.getId()+"";
name = customer.getName();
oldName = customer.getName();
address = customer.getAddress();
phone = customer.getPhone();
}else{
id= request.getParameter("id");
name = request.getParameter("oldName");
oldName = request.getParameter("oldName");
address = request.getParameter("address");
phone = request.getParameter("phone");
}
- WEB jsp在浏览器显示时超链接传递参数(name)乱码问题
https://www.cnblogs.com/whutwxj/p/5631135.html
5.1在超链接页面的接收参数处加代码()
<%response.setContentType("text/html;charset=UTF-8");
request.setCharacterEncoding("UTF-8"); %>
在接收出<% request.setCharacterEncoding("UTF-8");%>
5.2 配置字符编码过滤器
public class EncodingFilter extends HttpFilter {
private String encoding;
protected void init() {
encoding = getFilterConfig().getServletContext().getInitParameter("encoding");
}
public void doFilter(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
throws IOException, ServletException {
request.setCharacterEncoding(encoding);
filterChain.doFilter(request, response);
Web.xml
获取字符集
<context-param>
<param-name>encodingparam-name>
<param-value>UTF-8param-value>
context-param>
配置过滤器
<filter>
<filter-name>encodingFilterfilter-name>
<filter-class>zhe.EncodingFilterfilter-class>
filter>
<filter-mapping>
<filter-name>encodingFilterfilter-name>
<url-pattern>/encoding/*url-pattern>
filter-mapping>
- 有关文件的上传问题
设置两个响应头setContentType setHeader
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
get 请求下getwriter() 和getOutputStream() 不能同用!!!
//response.getWriter().append("Served at: ").append(request.getContextPath());
response.setContentType("application/x-msdownload");
String filename = "文件下载.pdf";
response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(filename, "UTF-8"));
OutputStream out = response.getOutputStream();String pdffilename = "C:\\Users\\Administrator\\Desktop\\铭牌.pdf";
InputStream in = new FileInputStream(pdffilename);
byte[] buffer = new byte[1024];
int len = 0;
while ((len = in.read(buffer)) != -1) {
out.write(buffer, 0, len);}
in.close();
- 报错 An erroe occurred see the old file
关于eclipse启动报错,an error has occurred.see the log file
https://blog.csdn.net/iku5200/article/details/80728911
提供解决方法一:
查看log文件,发现有这样的信息:
!MESSAGE The workspace exited with unsaved changes in the previous session; refreshing workspace to recover changes.
解决方案:
删除...\.metadata\.plugins\org.eclipse.core.resources\*.snap这个文件,重启Eclipse,成功。
方法二(我的问题已成功解决):
查看log文件,发现有这样的错误信息:
!MESSAGE FrameworkEvent ERROR
解决方案:cmd命令进eclipse,运行命令 eclipse.exe -clean后会自动打开软件,启动成功
方法三(来自百度知道):
是不是eclipse版本太新引起的,我在更新之后也出现了这样的问题,
解决方法:
1,打开eclipse安装目录下的eclipse.ini文件;
2,打开的文本文件最后添加一行
--add-modules=ALL-SYSTEM
3,保存重新打开Eclipse。
解决方法:
1,打开eclipse安装目录下的eclipse.ini文件;
2,打开的文本文件最后添加一行
--add-modules=ALL-SYSTEM
3,保存重新打开Eclipse。
方法四:
1.打开eclipse工作空间D:\eclipse\workspace\.metadata\.plugins\org.eclipse.core.resources找到.projects文件
2.打开.projects文件,删除该目录下所以工程里的.markers.snap和.syncinfo.snap文件
3.再次启动eclipse就OK了!
方法五:
打开eclipse\configuration\.settings\org.eclipse.ui.ide.prefs
删除RECENT_WORKSPACES等号后面的内容
- Hibernate自动创建数据表失败 (切换数据库方言)
lib\hibernate\hibernate-release-4.2.4.Final\project\etc\hibernate.properties
<property name="dialect">org.hibernate.dialect.MySQLDialectproperty>
- Hibernate创建数据表失败(映射文件)
hibernate.cfg.xml中的mapping映射不能重复映射
Caused by:org.hibernate.DuplicateMappingException: duplicate import ...
- Mysql数据库错误(数据库没有连接,在管理中打开数据库)
Mysql启动报错:错误代码10061
在eclipse运行时错误“Communications link failure”
- Txt文件出现乱码
在eclipse项目管理器中右键需要更改的txt文件,properties,找到text file encoding栏目,在other后边的框中输入GBK(可能备选项中没有,直接输入即可),然后APPLY即可
- springMVC中有关rest风格的DELETE和PUT用隐藏域出现的404
https://blog.csdn.net/weixin_45165669/article/details/104617304
@ResponseBody:在两个负责处理Delete请求和put请求的controller头部添加@ResponseBody,但只能显示除return的值
@ResponseBody 好用 在filter映射中加<servlet-name>mcpMvcservlet-name>
<filter-mapping>
<filter-name>HiddenHttpMethodFilterfilter-name>
<url-pattern>/*url-pattern>
<servlet-name>mcpMvcservlet-name>
filter-mapping>
- Neither BindingResult nor plain target object for bean name 'member' available
代码位置: springmm
SpringMVC REST风格的URL 删除操作失败 电脑弹出窗口application download did not succeed。 可能跟下方配置无关,自动好了0.0 下方配置位置:对应的相应页面
<jsp:useBean id="employee" class="zhe.springmvc.handler.HandlerTest" scope="request">jsp:useBean>
- Springmvc中有关数据的校验和异常国际化
1.使用JSR303验证标准
2.加入hibernate validator验证框架的jar包
3.在SpringMVC配置文件中添加
4.在bean属性上添加注解
@NotNull 不为空
private String lastName;
@Email 邮件格式
private String email;
@Past 生日
@DateTimeFormat(pattern = "yyyy-MM-dd")
private Date birth;
- 在目标方法bean类型的前面添加@Valid
- public String save(@Valid Employee employee,BindingResult result)
其实BindingResult也是一个errors类型,可以使用Errors代替BindingResult。
- Mysql数据库的配置
jdbc.user=root
jdbc.password=root
jdbc.driverClass=com.mysql.cj.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/spring?&useSSL=false&serverTimezone=UTC
- 有关JUnit测试出现not tests found...
出现此错误删除JUnit5重新导入,在项目中右击BuildPath 。。。
- 有关Mybatis的驼峰命名
举例:驼峰命名:数据库:last_name javaBean: lastName
<settings>
<setting name="mapUnderscoreToCamelCase" value="true"/>
settings>
配置在全局变量中,命名最好是没有下划线,不然出现个别的null;
是字段无法映射到对应的实体上,即charging_name(entity)->charging_name(database)
- Parameter 'ids' not found. Available parameters are [collection, list]
Mybatis 用动态sql语句foreach出现错误
DAO层:
public List getEmpsByConditionForeach(@Param ("ids") Listids );
Sql:
<select id="getEmpsByConditionForeach"
resultType="zhe.mybatis.bean.Employee"
parameterType="java.util.List">
- 关于Xshell连接Linux虚拟机Type `help' to learn how to use Xshell prompt
突然连不上,是突然。表示配置没有问题,可能是意外操作导致,比如关闭了VM的服务
控制面板\网络和 Internet\网络连接 VMware要开启
- 安装包下载速度太慢(阿里镜像)
所有东西下载慢的话就可以去找镜像!
官网下载太慢,我们可以使用淘宝镜像下载:http://npm.taobao.org/mirrors/git-for-windows/
- IDEA java错误:不支持发行版本5(修改idea显示的jdk版本按照安装的来)
https://www.pianshen.com/article/1152876419/
- log文件打不开的时候不要使用package和typeAilases指定扫描包
<typeAliases>
<typeAlias type="com.zhe.pojo.User" alias="User"/>
<package name="com.zhe.pojo"/> 通过包名,可以用类名小写user代替实体类
typeAliases>
- 学习spring的时候aop(面向切面)报错
Exception in thread "main" org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'users' is expected to be of type 'com.zhe.service.UserServiceImpl' but was actually of type 'com.sun.proxy.$Proxy3' 问题出在xml配置中
https://blog.csdn.net/xw12138/article/details/79802191
<aop:config>
aop:config>
- Mybatis连接数据库出现错误
Server returns invalid timezone. Go to 'Advanced' tab and set 'serverTimezone' property manually. (时区问题,修改serverTimezone)
- Mybatis整合spring
java.lang.ExceptionInInitializerError :db、log4j、依赖是否导入
java.lang.NullPointerException、org.apache.ibatis.exceptions.PersistenceException: 、org.apache.ibatis.session.defaults.DefaultSqlSessionFactory.openSessionFromDataSource
解决办法:mybatis-config.xml配置错误environments的配置