我使用放置在netbeans 6.9
中的struts 1.3.10
,/web-inf/ folder
个lib文件。
资源不可用404
显示http错误。
没有创建任何目录来单独放置动作,servlet文件。
al1文件在默认包中。
我是j2ee的新手请帮我解决我的问题..
提前谢谢..
的index.jsp:
<body>
<h1>Hello World!</h1>
<a href="mainpage">Main page</a>
</body>
mainpage.java:
out.println("<html>");
out.println("<head>");
out.println("<title>Servlet mainpage</title>");
out.println("</head>");
out.println("<body>");
out.println("<form action='strapp.action' method='post'>");
out.println("<input type='text' name='user'/><br>");
out.println("<input type='submit' name='Submit it'/>");
out.println("</form>");
out.println("</body>");
out.println("</html>");
strapp.java:
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
String c=(String)request.getParameter("user");
if(c==null)
{
return mapping.findForward("error");
}
return mapping.findForward("success");
}
}
success.java:
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
try {
out.println("<html>");
out.println("<head>");
out.println("<title>Servlet success</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>Servlet success at </h1>");
out.println("<p>Success page</p>");
out.println("</body>");
out.println("</html>");
} finally {
out.close();
}
}
error.java:
out.println("<html>");
out.println("<head>");
out.println("<title>Servlet error</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>Servlet error at </h1>");
out.println("<p>Error page</p>");
out.println("</body>");
out.println("</html>");
的struts-config.xml:
<action-mappings>
<action name="strapp" class="strapp" path="/strapp.action" >
<forward name="success" path="/success.java"/>
<forward name="error" path="/error.java"/>
</action>
</action-mappings>
的web.xml:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.3//EN"
"http://jakarta.apache.org/struts/dtds/struts-config_1_3.dtd">
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
<init-param>
<param-name>debug</param-name>
<param-value>2</param-value>
</init-param>
<init-param>
<param-name>detail</param-name>
<param-value>2</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
答案 0 :(得分:0)
的struts-config.xml:
<action-mappings>
<action name="strapp" class="strapp" path="/strapp.action" >
<forward name="success" path="/success.java"/>
<forward name="error" path="/error.java"/>
</action>
</action-mappings>
success.java和error.java的含义是什么,必须在web.xml中指定servlet,否则结构无法找到正确的目标。 你可以看到结构的例子。