Home > Back-end >  Can't access the contents of the controller
Can't access the contents of the controller

Time:09-23

Web.xml
<? The XML version="1.0" encoding="utf-8"?>
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 "& gt;

ContextConfigLocation
The classpath: applicationContext. Xml


Org. Springframework. Web. Context. ContextLoaderListener



Springmvc

Org. Springframework. Web. Servlet. DispatcherServlet

ContextConfigLocation
The classpath: for springmvc. Xml

1


Springmvc
/


Encoding

Org. Springframework. Web. Filter. CharacterEncodingFilter

Encoding
Utf-8 & lt;/param - value>



Encoding
/* & lt;/url - pattern>


XML for springmvc.
<? The XML version="1.0" encoding="utf-8"?>
XMLNS: xsi="http://www.w3.org/2001/XMLSchema-instance"
XMLNS: MVC="http://www.springframework.org/schema/mvc"
XMLNS: context="http://www.springframework.org/schema/context"
Xsi: schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd "& gt;







The controller class
Package com. BJSXT. Controller;

import java.io.File;
import java.io.IOException;
Import the Java. Util. UUID;

The import javax.mail. The annotation. The Resource;
The import javax.mail. Servlet. HTTP. It;

import org.apache.commons.io.FileUtils;
The import org. Springframework. Stereotype. The Controller;
The import org. Springframework. Web. Bind. The annotation. RequestMapping;
The import org. Springframework. Web. Multipart. MultipartFile;

The import com. BJSXT. Pojo. Users;
The import com. BJSXT. Service. UsersService;


@ Controller
Public class UsersController {
@ the Resource
Private UsersService usersServiceImpl;
@ RequestMapping (" register ")
Public String register (Users Users, MultipartFile file, it the req) {
String fileName=UUID. RandomUUID (). The toString () + file. GetOriginalFilename (). The substring (file. GetOriginalFilename (). The lastIndexOf (". "));
String path=the req. GetServletContext (.) getRealPath (" images ") + "/" + fileName.
//controller can no longer be an exception is thrown outwards thought no class to handle the
Try {
FileUtils. CopyInputStreamToFile (file. GetInputStream (), the new file (path));
} the catch (IOException e) {
e.printStackTrace();
}
//only to wapps
Users. SetPhoto (fileName);
System. The out. Println (" hello world ");
Int index=usersServiceImpl. InsRegister (users);
If (index> 0 {
Return "/main. JSP";
} else {
The return of "redirect:/register. JSP";
}

}
}
  • Related