ssh2整合问题,struts2 页面访问不到Action里面的方法

struts.xml

 <?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
    <constant name="struts.devMode" value="true"/>
    <constant name="struts.i18n.encoding" value="UTF-8" />
    <constant name="struts.convention.result.path" value="/WEB-INF/jsp"/>
    <constant name="struts.convention.package.locators" value="web,action"/>
    <constant name="struts.objectFactory" value="spring"/>
    <constant name="struts.configuration.xml.reload" value="true"/>
    <package name="demo" extends="struts-default" namespace="/demo" />
</struts>

web.xml

 <filter>
        <filter-name>struts2</filter-name>
        <filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class>
        <init-param>
        <param-name>filterConfig</param-name>
        <param-value>classpath:struts/struts.xml</param-value>
    </init-param>
    </filter>

    <!-- 配置struts2映射 -->
    <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

Action.java

 package com.sshf.action;
import java.util.Map;
import javax.annotation.Resource;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.sshf.model.PhsaUser;
import com.sshf.service.UserService;

@Component
@Namespace("/demo")
@Scope("prototype")
public class UserAction extends ActionSupport{

    private static final long serialVersionUID = 1L;

    @Resource
    private UserService userService;

    private PhsaUser user;
    private String id;

    @Action(value="queryUser",results={
            @Result(name="success",location="/WEB-INF/jsp/success.jsp"),
            @Result(name="error",location="/WEB-INF/jsp/error.jsp")})
    public String queryUser() throws Exception{
        //Integer userId=this.getUser().getId();
        Integer uId=Integer.parseInt(this.getId());
        PhsaUser user = userService.queryById(uId);
        if(user!=null){
            ActionContext actionContext = ActionContext.getContext();
            Map<String,Object> session= actionContext.getSession();
            session.put("user",user);
            return SUCCESS;
        }
        return ERROR;
    }
    ........id set/get...
}

queryUser.jsp


<form action="/demo/queryUser" method="post">
    查找id:<input type="text" name="id"/><br>
    <input type="submit" value="check"/>    
</form>

5个回答

form表单要提交全路径

全路径了也不行啊

 <form action="/sshf/demo/queryUser" method="post">
    查找id:<input type="text" name="id"/><br>
    <input type="submit" value="check"/>    
</form>

也不行

 <form action="<%=request.getContextPath()%>/demo/queryUser" method="post">
    查找id:<input type="text" name="id"/><br>
    <input type="submit" value="check"/>    
</form>

@ParentPackage("struts-default")

这个配置下试试

加了

 @ParentPackage("struts-default")

也没用

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐