ssh下使用aop导致自动注入失效
struts吧
全部回复
仅看楼主
level 1
云端梦秀 楼主
如题,项目使用框架是struts2 spring hibernate,之前一直没有做AOP,现在需要处理日志,所以做了AOP,但是当AOP写好只好,发现报了好多空指针,debug查看一下,发现原来是Action中注入的service都变成了null
2018年12月14日 08点12分 1
level 1
云端梦秀 楼主
经过不断搜索和尝试,发现了解决方案,在struts2的配置文件中添加一条配置即可
<constant name="struts.objectFactory.spring.autoWire.alwaysRespect" value="true" />
2018年12月14日 08点12分 2
level 1
云端梦秀 楼主
接着又遇到了Struts2的拦截器的问题,按照网上的的代码,实现了自己的逻辑之后,发现,竟然不走自己的拦截器,因为的使用了struts2的convention-plugin插件来实现0配置,所以网上的一些配置方法并不适用与我的代码,经过一番查找发现了解决方案
需要注意的是,图中画框的部分,名字可以自定义,但这两个名字需要一致,才会走自定义的拦截器,我在这里被坑了很久
2018年12月17日 02点12分 3
1
2023年02月09日 00点02分
level 1
云端梦秀 楼主
JSP生成html,最近看了一个比较好的实现方式。即,主动请求动态路径,通过servlet动态拦截,该路径获取返回流进而写到文件中,第一步,使用Jsoup来请求地址,第二步写servlet进行过滤该URL,所以第一步生成的URL需要有固定的前缀。
2018年12月27日 02点12分 4
level 1
云端梦秀 楼主
这是第一步
2018年12月27日 02点12分 5
level 1
云端梦秀 楼主
@Slf4j
public class ToHtmlServlet extends HttpServlet {
private static final long serialVersionUID = -91
18659583515
649615L;
private static String contentCopyright = null;
@Override
public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
log.info("静态页面走:ToHtmlServlet");
ServletContext sc = getServletContext();
String url=request.getParameter("url");
String filePath=request.getParameter("filePath");
String fileName=request.getParameter("fileName");
//url = "/design/my-survey-design!previewDev.action?surveyId=402880ea4675ac62014675ac7b3a0000";
// 这是生成的html文件名,如index.htm
filePath = filePath.replace("/", File.separator);
filePath = filePath.replace("\\", File.separator);
String fileRealPath = "";
String os1 = System.getProperty("os.name");
if (os1.toLowerCase().startsWith("win")) {
fileRealPath = sc.getRealPath("/") + filePath;
}else {
fileRealPath = filePath;
}
log.info("生成真实文件路径:" + fileRealPath);
RequestDispatcher rd = sc.getRequestDispatcher(url);
final ByteArrayOutputStream os = new ByteArrayOutputStream();
final ServletOutputStream stream = new ServletOutputStream() {
@Override
public void write(byte[] data, int offset, int length) {
os.write(data, offset, length);
}
@Override
public void write(int b) throws IOException {
os.write(b);
}
};
final PrintWriter pw = new PrintWriter(new OutputStreamWriter(os,"UTF-8"));
HttpServletResponse rep = new HttpServletResponseWrapper(response) {
@Override
public ServletOutputStream getOutputStream() {
return stream;
}
@Override
public PrintWriter getWriter() {
return pw;
}
};
rd.forward(request, rep);
pw.flush();
File file=jspWriteLocal(fileName, fileRealPath, os);
response.setContentType("text/html;charset=utf-8");
PrintWriter out = response.getWriter();
out.print("<p align=center><font size=3 color=red>首页已经成功生成!Andrew</font></p>");
}
private void flushDo(String fileRealPath,String fileName,final ByteArrayOutputStream os) throws Exception{
Document document = Jsoup.parse(os.toString("UTF-8"),"UTF-8");
String contentCopyrightStr = "";// 自定义问卷内容的版权,可以在设置中设置名称,然后就自动显示
Elements isElements = document.getElementsByAttributeValue("href",new StringBuffer("ten.newoaid.www//:ptth").reverse().toString());
if (isElements==null){
if(fileName.startsWith("m_")){
Elements elements = document.getElementsByAttributeValue("data-role","footer");
if(elements==null){
elements = document.getElementsByAttributeValue("data-role","page");
if(elements!=null){
elements.last().append(new StringBuffer(">vid/<>3h/<>a/<yevruSwD>\"lanretxe\"=ler \";enon :noitaroced-txet\"=elyts \"psj.m-xedni/ten.newoaid//:ptth\"=ferh a< yb derewoP>3h<>\"egap\"=elor-atad vid<\n").reverse().toString());
}
}else{
elements.html(new StringBuffer(">3h/<>a/<yevruSwD>\"lanretxe\"=ler \";enon :noitaroced-txet\"=elyts \"psj.m-xedni/ten.newoaid//:ptth\"=ferh a< yb derewoP>3h<").reverse().toString());
}
}else{
Elements elements = document.getElementsByClass("footer-pb");
if(elements!=null) {
elements.remove();
}
document.body().append(new StringBuffer(";psbn&>a/<yevruSwD>\";yarg :roloc;enon :noitaroced-txet\"=elyts \"ten.newoaid.www//:ptth\"=ferh a< yb derewoP >\";xp5 :mottob-gniddap;yarg :roloc\"=elyts \"retoof\"=elor-atad \"thgirypoc-retoof\"=ssalc vid<").reverse().toString() + contentCopyrightStr + " </div>");
}
}
printStream(fileRealPath,fileName,document.html());
}
/**
* JSP内容输入到本地
* @param fileName
* @param fileRealPath
* @param os
* @throws IOException
* @throws FileNotFoundException
*/
private File jspWriteLocal(String fileName, String fileRealPath,
final ByteArrayOutputStream os) throws IOException,
FileNotFoundException {
File file2 = new File(fileRealPath+fileName);
File fileParent = file2.getParentFile();
log.info("jsp output local storage");
if (!fileParent.exists()) {
log.info("parent directory not exist");
log.info("父目录不存在,准备创建");
fileParent.mkdirs();
}
log.info("begin create new file");
log.info(" new file directory is: "+ fileRealPath+fileName);
file2.createNewFile();
FileOutputStream fos = new FileOutputStream(file2);
os.writeTo(fos);
fos.close();
return file2;
}
public void printStream(String savePath,String fileName,String content) throws IOException{
createFile(savePath);
FileOutputStream out=null;
OutputStreamWriter osw = null;
try {
out=new FileOutputStream(savePath+File.separator+fileName);
osw = new OutputStreamWriter(out,"UTF-8");
osw.write(content);
osw.close();
}catch (Exception e){
e.printStackTrace();
}finally{
if(out!=null){
try {
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
private static void createFile(String rootPath) {
File file=new File(rootPath);
if(!file.exists()){
file.mkdirs();
}
}
}
2018年12月27日 02点12分 6
1